Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload udev rules after change #485

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ The following parameters are available in the `systemd` class:
* [`udev_resolve_names`](#-systemd--udev_resolve_names)
* [`udev_timeout_signal`](#-systemd--udev_timeout_signal)
* [`udev_rules`](#-systemd--udev_rules)
* [`udev_reload`](#-systemd--udev_reload)
* [`machine_info_settings`](#-systemd--machine_info_settings)
* [`manage_logind`](#-systemd--manage_logind)
* [`logind_settings`](#-systemd--logind_settings)
Expand Down Expand Up @@ -525,6 +526,14 @@ Config Hash that is used to generate instances of our

Default value: `{}`

##### <a name="-systemd--udev_reload"></a>`udev_reload`

Data type: `Boolean`

Whether udev rules should be automatically reloaded upon change.

Default value: `false`

##### <a name="-systemd--machine_info_settings"></a>`machine_info_settings`

Data type: `Systemd::MachineInfoSettings`
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
# Config Hash that is used to generate instances of our
# `udev::rule` define.
#
# @param udev_reload
# Whether udev rules should be automatically reloaded upon change.
#
# @param machine_info_settings
# Settings to place into /etc/machine-info (hostnamectl)
#
Expand Down Expand Up @@ -261,6 +264,7 @@
Optional[Integer] $udev_event_timeout = undef,
Optional[Enum['early', 'late', 'never']] $udev_resolve_names = undef,
Optional[Variant[Integer,String]] $udev_timeout_signal = undef,
Boolean $udev_reload = false,
Boolean $manage_logind = false,
Systemd::LogindSettings $logind_settings = {},
Boolean $manage_all_network_files = false,
Expand Down
12 changes: 11 additions & 1 deletion manifests/udev/rule.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,22 @@
fail("systemd::udev::rule - ${name}: param rules is empty, you need to pass rules")
}

if $systemd::udev_reload {
if $notify_services =~ Array {
$_notify = $notify_services << 'Exec[systemd-udev_reload]'
} else {
$_notify = [$notify_services, 'Exec[systemd-udev_reload]']
}
} else {
$_notify = $notify_services
}
deric marked this conversation as resolved.
Show resolved Hide resolved

file { join([$path, $name], '/'):
ensure => $ensure,
owner => 'root',
group => 'root',
mode => '0444',
notify => $notify_services,
notify => $_notify,
selinux_ignore_defaults => $selinux_ignore_defaults,
content => epp("${module_name}/udev_rule.epp", { 'rules' => $rules }),
}
Expand Down
6 changes: 6 additions & 0 deletions manifests/udevd.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@
* => $udev_rule,
}
}

exec { 'systemd-udev_reload':
command => 'udevadm control --reload-rules && udevadm trigger',
refreshonly => true,
path => $facts['path'],
}
}
5 changes: 5 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@
let(:params) do
{
manage_udevd: true,
udev_reload: true,
udev_log: 'daemon',
udev_children_max: 1,
udev_exec_delay: 2,
Expand All @@ -664,6 +665,7 @@
{
manage_udevd: true,
udev_purge_rules: true,
udev_reload: true,
}
end

Expand Down Expand Up @@ -701,6 +703,9 @@
'ACTION=="add", KERNEL=="sdb", RUN+="/bin/raw /dev/raw/raw2 %N"',
])
}

it { is_expected.to contain_exec('systemd-udev_reload') }
it { is_expected.to contain_file('/etc/udev/rules.d/example_raw.rules').that_notifies('Exec[systemd-udev_reload]') }
end

context 'with machine-info' do
Expand Down
19 changes: 18 additions & 1 deletion spec/defines/udev_rules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,24 @@ class { 'systemd': manage_udevd => true, manage_journald => false }
it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify([]) }
end

describe 'ensured absent with notify' do
describe 'ensured absent with automatic reload' do
let(:pre_condition) do
<<-PUPPET
class { 'systemd': manage_udevd => true, manage_journald => false, udev_reload => true }
PUPPET
end
let(:params) do
{
ensure: 'absent',
}
end

it { is_expected.to compile.with_all_deps }

it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) }
end

describe 'ensured absent with custom notify' do
let(:params) { { ensure: 'absent', notify_services: 'Service[systemd-udevd]', } }

it { is_expected.to compile.with_all_deps }
Expand Down
Loading