|
1 | 1 | # @summary Manage a user service running under systemd --user |
2 | 2 | # |
3 | 3 | # @example Enable a service for all users |
| 4 | +# class { 'systemd': |
| 5 | +# install_runuser => true, |
| 6 | +# } |
4 | 7 | # systemd::user_service { 'systemd-tmpfiles-clean.timer': |
5 | 8 | # enable => true, |
6 | 9 | # global => true, |
|
74 | 77 | } |
75 | 78 | } else { # per user services |
76 | 79 |
|
77 | | - $_systemctl_user = [ |
78 | | - 'systemd-run', '--pipe', '--wait', '--user', '--machine', "${user}@.host", |
79 | | - 'systemctl', '--user', |
80 | | - ] |
81 | | - |
82 | 80 | # To accept notifies of this type. |
83 | 81 | exec { "try-reload-or-restart-${user}-${unit}": |
84 | | - command => $_systemctl_user + ['try-reload-or-restart', $unit], |
| 82 | + command => systemd::systemctl_user($user, ['try-reload-or-restart', $unit]), |
85 | 83 | refreshonly => true, |
86 | 84 | path => $facts['path'], |
87 | 85 | } |
88 | 86 |
|
89 | 87 | if $_ensure { |
90 | 88 | $_ensure_title = "Start user service ${unit} for user ${user}" |
91 | | - $_ensure_command = $_systemctl_user + ['start', $unit] |
92 | | - $_ensure_unless = [$_systemctl_user + ['is-active', $unit]] |
| 89 | + $_ensure_command = systemd::systemctl_user($user, ['start',$unit]) |
| 90 | + $_ensure_unless = [systemd::systemctl_user($user, ['is-active',$unit])] |
93 | 91 | $_ensure_onlyif = undef |
94 | 92 |
|
95 | 93 | # Don't reload just after starting |
96 | 94 | Exec["try-reload-or-restart-${user}-${unit}"] -> Exec[$_ensure_title] |
97 | 95 | } else { |
98 | 96 | $_ensure_title = "Stop user service ${unit} for user ${user}" |
99 | | - $_ensure_command = $_systemctl_user + ['stop', $unit] |
| 97 | + $_ensure_command = systemd::systemctl_user($user, ['stop', $unit]) |
100 | 98 | $_ensure_unless = undef |
101 | | - $_ensure_onlyif = [$_systemctl_user + ['is-active', $unit]] |
| 99 | + $_ensure_onlyif = [systemd::systemctl_user($user, ['is-active',$unit])] |
102 | 100 | } |
103 | 101 |
|
104 | 102 | exec { $_ensure_title: |
|
110 | 108 |
|
111 | 109 | if $enable { |
112 | 110 | $_enable_title = "Enable user service ${unit} for user ${user}" |
113 | | - $_enable_command = $_systemctl_user + ['enable', $unit] |
114 | | - $_enable_unless = [$_systemctl_user + ['is-enabled', $unit]] |
| 111 | + $_enable_command = systemd::systemctl_user($user, ['enable', $unit]) |
| 112 | + $_enable_unless = [systemd::systemctl_user($user, ['is-enabled', $unit])] |
115 | 113 | $_enable_onlyif = undef |
116 | 114 |
|
117 | 115 | # Puppet does this for services so lets copy that logic |
|
121 | 119 | } |
122 | 120 | } else { |
123 | 121 | $_enable_title = "Disable user service ${unit} for user ${user}" |
124 | | - $_enable_command = $_systemctl_user + ['disable', $unit] |
| 122 | + $_enable_command = systemd::systemctl_user($user, ['disable', $unit]) |
125 | 123 | $_enable_unless = undef |
126 | | - $_enable_onlyif = [$_systemctl_user + ['is-enabled', $unit]] |
| 124 | + $_enable_onlyif = [systemd::systemctl_user($user, ['is-enabled', $unit])] |
127 | 125 | } |
128 | 126 |
|
129 | 127 | exec { $_enable_title: |
|
0 commit comments