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

Manage logind service and configuration #120

Merged
merged 2 commits into from Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Expand Up @@ -167,13 +167,16 @@ systemd::network{'eth0.network':
### Services

Systemd provides multiple services. Currently you can manage `systemd-resolved`,
`systemd-timesyncd` and `systemd-networkd` via the main class:
`systemd-timesyncd`, `systemd-networkd`, `systemd-journald` and `systemd-logind`
via the main class:

```puppet
class{'systemd':
manage_resolved => true,
manage_networkd => true,
manage_timesyncd => true,
manage_journald => true,
manage_logind => true,
}
```

Expand Down Expand Up @@ -226,3 +229,16 @@ systemd::journald_settings:
MaxLevelStore:
ensure: absent
```

### logind configuration

It also allows you to manage logind settings. You can manage logind settings through setting the `logind_settings` parameter. If you want a parameter to be removed, you can pass its value as params.

```yaml
systemd::logind_settings:
HandleSuspendKey: 'ignore'
KillUserProcesses: 'no'
RemoveIPC:
ensure: absent
UserTasksMax: 10000
```
2 changes: 2 additions & 0 deletions data/common.yaml
Expand Up @@ -23,3 +23,5 @@ systemd::accounting: {}
systemd::purge_dropin_dirs: true
systemd::manage_journald: true
systemd::journald_settings: {}
systemd::manage_logind: false
systemd::logind_settings: {}
12 changes: 12 additions & 0 deletions manifests/init.pp
Expand Up @@ -75,6 +75,12 @@
# @param journald_settings
# Config Hash that is used to configure settings in journald.conf
#
# @param manage_logind
# Manage the systemd logind
#
# @param logind_settings
# Config Hash that is used to configure settings in logind.conf
#
class systemd (
Hash[String,Hash[String, Any]] $service_limits,
Boolean $manage_resolved,
Expand All @@ -100,6 +106,8 @@
Boolean $purge_dropin_dirs,
Boolean $manage_journald,
Systemd::JournaldSettings $journald_settings,
Boolean $manage_logind,
Systemd::LogindSettings $logind_settings,
){

contain systemd::systemctl::daemon_reload
Expand All @@ -125,4 +133,8 @@
if $manage_journald {
contain systemd::journald
}

if $manage_logind {
contain systemd::logind
}
}
31 changes: 31 additions & 0 deletions manifests/logind.pp
@@ -0,0 +1,31 @@
# **NOTE: THIS IS A [PRIVATE](https://github.com/puppetlabs/puppetlabs-stdlib#assert_private) CLASS**
fraenki marked this conversation as resolved.
Show resolved Hide resolved
#
# This class manages systemd's login manager configuration.
#
# https://www.freedesktop.org/software/systemd/man/logind.conf.html
class systemd::logind {

assert_private()

service{'systemd-logind':
ensure => running,
}
$systemd::logind_settings.each |$option, $value| {
ini_setting{
$option:
path => '/etc/systemd/logind.conf',
section => 'Login',
setting => $option,
notify => Service['systemd-logind'],
}
if $value =~ Hash {
Ini_setting[$option]{
* => $value,
}
} else {
Ini_setting[$option]{
value => $value,
}
}
}
}
45 changes: 45 additions & 0 deletions spec/classes/init_spec.rb
Expand Up @@ -208,6 +208,51 @@
it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_service('systemd-journald') }
end

context 'when enabling logind with options' do
let(:params) do
{
:manage_logind => true,
:logind_settings => {
'HandleSuspendKey' => 'ignore',
'KillUserProcesses' => 'no',
'RemoveIPC' => {
'ensure' => 'absent',
},
'UserTasksMax' => '10000',
}
}
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_service('systemd-logind').with(
:ensure => 'running'
) }
it { is_expected.to have_ini_setting_resource_count(4) }
it { is_expected.to contain_ini_setting('HandleSuspendKey').with(
:path => '/etc/systemd/logind.conf',
:section => 'Login',
:notify => 'Service[systemd-logind]',
:value => 'ignore',
)}
it { is_expected.to contain_ini_setting('KillUserProcesses').with(
:path => '/etc/systemd/logind.conf',
:section => 'Login',
:notify => 'Service[systemd-logind]',
:value => 'no',
)}
it { is_expected.to contain_ini_setting('RemoveIPC').with(
:path => '/etc/systemd/logind.conf',
:section => 'Login',
:notify => 'Service[systemd-logind]',
:ensure => 'absent',
)}
it { is_expected.to contain_ini_setting('UserTasksMax').with(
:path => '/etc/systemd/logind.conf',
:section => 'Login',
:notify => 'Service[systemd-logind]',
:value => '10000',
)}
end
end
end
end
Expand Down
29 changes: 29 additions & 0 deletions types/logindsettings.pp
@@ -0,0 +1,29 @@
# Matches Systemd Login Manager Struct
type Systemd::LogindSettings = Struct[
{
Optional['HandleHibernateKey'] => Variant[Enum['ignore','poweroff','reboot','halt','kexec','suspend','hibernate','hybrid-sleep','suspend-then-hibernate','lock'],Systemd::LogindSettings::Ensure],
Optional['HandleLidSwitch'] => Variant[Enum['ignore','poweroff','reboot','halt','kexec','suspend','hibernate','hybrid-sleep','suspend-then-hibernate','lock'],Systemd::LogindSettings::Ensure],
Optional['HandleLidSwitchDocked'] => Variant[Enum['ignore','poweroff','reboot','halt','kexec','suspend','hibernate','hybrid-sleep','suspend-then-hibernate','lock'],Systemd::LogindSettings::Ensure],
Optional['HandleLidSwitchExternalPower'] => Variant[Enum['ignore','poweroff','reboot','halt','kexec','suspend','hibernate','hybrid-sleep','suspend-then-hibernate','lock'],Systemd::LogindSettings::Ensure],
Optional['HandlePowerKey'] => Variant[Enum['ignore','poweroff','reboot','halt','kexec','suspend','hibernate','hybrid-sleep','suspend-then-hibernate','lock'],Systemd::LogindSettings::Ensure],
Optional['HandleSuspendKey'] => Variant[Enum['ignore','poweroff','reboot','halt','kexec','suspend','hibernate','hybrid-sleep','suspend-then-hibernate','lock'],Systemd::LogindSettings::Ensure],
Optional['HibernateKeyIgnoreInhibited'] => Variant[Enum['yes','no'],Systemd::LogindSettings::Ensure],
Optional['HoldoffTimeoutSec'] => Variant[Integer,Systemd::LogindSettings::Ensure],
Optional['IdleAction'] => Variant[Enum['ignore','poweroff','reboot','halt','kexec','suspend','hibernate','hybrid-sleep','suspend-then-hibernate','lock'],Systemd::LogindSettings::Ensure],
Optional['IdleActionSec'] => Variant[Integer,Systemd::LogindSettings::Ensure],
Optional['InhibitDelayMaxSec'] => Variant[Integer,Systemd::LogindSettings::Ensure],
Optional['InhibitorsMax'] => Variant[Integer,Systemd::LogindSettings::Ensure],
Optional['KillExcludeUsers'] => Variant[Array[String],Systemd::LogindSettings::Ensure],
Optional['KillOnlyUsers'] => Variant[Array[String],Systemd::LogindSettings::Ensure],
Optional['KillUserProcesses'] => Variant[Enum['yes','no'],Systemd::LogindSettings::Ensure],
Optional['LidSwitchIgnoreInhibited'] => Variant[Enum['yes','no'],Systemd::LogindSettings::Ensure],
Optional['NAutoVTs'] => Variant[Integer,Systemd::LogindSettings::Ensure],
Optional['PowerKeyIgnoreInhibited'] => Variant[Enum['yes','no'],Systemd::LogindSettings::Ensure],
Optional['RemoveIPC'] => Variant[Enum['yes','no'],Systemd::LogindSettings::Ensure],
Optional['ReserveVT'] => Variant[Integer,Systemd::LogindSettings::Ensure],
Optional['RuntimeDirectorySize'] => Variant[Integer,Pattern['^(\d+(K|M|G|T|P|E|%)?)$'],Systemd::LogindSettings::Ensure],
Optional['SessionsMax'] => Variant[Integer,Pattern['^(infinity|(\d+(K|M|G|T|P|E|%)?))$'],Systemd::LogindSettings::Ensure],
Optional['SuspendKeyIgnoreInhibited'] => Variant[Enum['yes','no'],Systemd::LogindSettings::Ensure],
Optional['UserTasksMax'] => Variant[Integer,Pattern['^(infinity|(\d+(K|M|G|T|P|E|%)?))$'],Systemd::LogindSettings::Ensure]
}
]
1 change: 1 addition & 0 deletions types/logindsettings/ensure.pp
@@ -0,0 +1 @@
type Systemd::LogindSettings::Ensure = Struct[{'ensure' => Enum['present','absent']}]