Skip to content

Commit 6fb4386

Browse files
committed
python: Unify systemd drop-in creation
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent ae00d43 commit 6fb4386

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

python/lib/setup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,8 @@ def configure_trusted_networking():
216216
no_s_flag_conf_txt = ('[Service]\n'
217217
'ExecStart=\n'
218218
'ExecStart=/usr/bin/nm-online -q\n')
219-
lib.utils.run([
220-
'systemctl', 'edit', '--stdin', '--drop-in', 'no-s-flag',
221-
'NetworkManager-wait-online.service'
222-
],
223-
input=no_s_flag_conf_txt)
219+
lib.utils.systemd_drop_in('NetworkManager-wait-online.service', 'no-s-flag',
220+
no_s_flag_conf_txt)
224221

225222

226223
def disable_suspend():

python/lib/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ def run_check_rc_zero(*args, **kwargs):
221221
return chronic(*args, **kwargs, check=False).returncode == 0
222222

223223

224+
def systemd_drop_in(service, drop_in_name, conf_txt):
225+
return run0(['systemctl', 'edit', '--stdin', '--drop-in', drop_in_name, service],
226+
input=conf_txt)
227+
228+
224229
def tg_msg(raw_msg):
225230
if not (botinfo := Path.home().joinpath('.botinfo')).exists():
226231
raise FileNotFoundError(f"{botinfo} could not be found!")

python/scripts/sd_nspawn.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ def _gen_upd_cmd(self):
276276
def install_files(self):
277277
lib.utils.request_root('file creation')
278278

279-
systemctl_edit_cmd = ['systemctl', 'edit', '--stdin']
280-
281279
# Allow containers started as services to access /dev/kvm to run
282280
# accelerated VMs, which allows avoiding installing QEMU in the host
283281
# environment. Add /dev/vhost-vsock, /dev/vhost-net, and /dev/vsock if
@@ -293,17 +291,14 @@ def install_files(self):
293291
kvm_conf_txt_parts = ['[Service]\n'] + [
294292
f"DeviceAllow={mount} rw\n" for mount in available_dev_mounts
295293
]
296-
297-
lib.utils.run0([*systemctl_edit_cmd, '--drop-in=kvm', 'systemd-nspawn@.service'],
298-
input=''.join(kvm_conf_txt_parts))
294+
lib.utils.systemd_drop_in('systemd-nspawn@.service', 'kvm', ''.join(kvm_conf_txt_parts))
299295

300296
# For Mac Studio, ensure the container only starts once the network is online
301297
if lib.utils.get_hostname() == 'mac-studio-m1-max':
302298
network_conf_txt = ('[Unit]\n'
303299
'After=network-online.target\n'
304300
'Wants=network-online.target\n')
305-
lib.utils.run0([*systemctl_edit_cmd, '--drop-in=network', 'systemd-nspawn@.service'],
306-
input=network_conf_txt)
301+
lib.utils.systemd_drop_in('systemd-nspawn@.service', 'network', network_conf_txt)
307302

308303
# Allow my user to access 'machinectl shell' without authentication
309304
# rules.d can only be read by root so we need to use sudo to test

python/setup/arch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ def enable_reflector():
290290
'OnUnitInactiveSec=18h\n'
291291
'OnCalendar=*-*-* 06,18:00:00\n'
292292
'RandomizedDelaySec=1h\n')
293-
lib.utils.run(['systemctl', 'edit', '--stdin', '--drop-in=00-schedule', 'reflector.timer'],
294-
input=reflector_drop_in_text)
293+
lib.utils.systemd_drop_in('reflector.timer', '00-schedule', reflector_drop_in_text)
295294
lib.utils.run(['systemctl', 'daemon-reload'])
296295

297296
lib.setup.systemctl_enable('reflector.timer')

0 commit comments

Comments
 (0)