From: Lennart Poettering Date: Fri, 23 May 2025 13:41:58 +0000 (+0200) Subject: units: add units for vmspawn/nspawn in --user mode too X-Git-Tag: v258-rc1~79^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48cb009afc07fbc6634612ff66088a09acd554fc;p=thirdparty%2Fsystemd.git units: add units for vmspawn/nspawn in --user mode too --- diff --git a/units/machines.target b/units/machines.target index 165839aeb17..b7a84f48147 100644 --- a/units/machines.target +++ b/units/machines.target @@ -8,7 +8,7 @@ # (at your option) any later version. [Unit] -Description=Containers +Description=Virtual Machine and Containers Documentation=man:systemd.special(7) Before=multi-user.target diff --git a/units/user/machine.slice b/units/user/machine.slice new file mode 100644 index 00000000000..fe729d0eb90 --- /dev/null +++ b/units/user/machine.slice @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +[Unit] +Description=Virtual Machine and Container Slice +Documentation=man:systemd.special(7) diff --git a/units/user/machines.target b/units/user/machines.target new file mode 100644 index 00000000000..35a99666bb4 --- /dev/null +++ b/units/user/machines.target @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +[Unit] +Description=Virtual Machines and Containers +Documentation=man:systemd.special(7) +Before=default.target + +[Install] +WantedBy=default.target diff --git a/units/user/meson.build b/units/user/meson.build index c669e4bb1cb..d8d3d9fdac5 100644 --- a/units/user/meson.build +++ b/units/user/meson.build @@ -10,6 +10,14 @@ units = [ { 'file' : 'exit.target' }, { 'file' : 'graphical-session-pre.target' }, { 'file' : 'graphical-session.target' }, + { + 'file' : 'machine.slice', + 'conditions' : ['ENABLE_MACHINED'], + }, + { + 'file' : 'machines.target', + 'conditions' : ['ENABLE_MACHINED'], + }, { 'file' : 'paths.target' }, { 'file' : 'printer.target' }, { 'file' : 'session.slice' }, @@ -26,6 +34,14 @@ units = [ { 'file' : 'systemd-tmpfiles-clean.service' }, { 'file' : 'systemd-tmpfiles-clean.timer' }, { 'file' : 'systemd-tmpfiles-setup.service' }, + { + 'file' : 'systemd-nspawn@.service.in', + 'conditions' : ['ENABLE_NSPAWN'], + }, + { + 'file' : 'systemd-vmspawn@.service.in', + 'conditions' : ['ENABLE_VMSPAWN'], + }, { 'file' : 'timers.target' }, { 'file' : 'xdg-desktop-autostart.target', @@ -34,7 +50,17 @@ units = [ ] foreach unit : units - file = unit.get('file') + source = unit.get('file') + + if source.endswith('.in') + needs_jinja = true + name = source.substring(0, -3) + assert(name + '.in' == source) + else + needs_jinja = false + name = source + endif + source = files(source) install = true foreach cond : unit.get('conditions', []) @@ -44,20 +70,30 @@ foreach unit : units endif endforeach - if install - install_data(file, + if needs_jinja + t = custom_target( + name, + input : source, + output : name, + command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'], + install : install, + install_dir : userunitdir) + elif install + install_data(source, install_dir : userunitdir) + endif + if install foreach target : unit.get('symlinks', []) if target.endswith('/') # '/' is only allowed at the end of the target assert(target.replace('/', '') + '/' == target) - install_symlink(file, - pointing_to : '..' / file, + install_symlink(name, + pointing_to : '..' / name, install_dir : userunitdir / target) else install_symlink(target, - pointing_to : file, + pointing_to : name, install_dir : userunitdir) endif endforeach diff --git a/units/user/systemd-nspawn@.service.in b/units/user/systemd-nspawn@.service.in new file mode 100644 index 00000000000..90fdc0cb486 --- /dev/null +++ b/units/user/systemd-nspawn@.service.in @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +[Unit] +Description=Container %i +Documentation=man:systemd-nspawn(1) +PartOf=machines.target +Before=machines.target + +[Service] +ExecStart=systemd-nspawn --quiet --keep-unit --register=yes --boot --network-veth -U --settings=override --machine=%i +ExecStopPost=systemd-nspawn --cleanup --machine=%i +KillMode=mixed +Type=notify +RestartForceExitStatus=133 +SuccessExitStatus=133 +Slice=machine.slice +Delegate=yes +DelegateSubgroup=supervisor +CoredumpReceive=yes +TasksMax=16384 +{{SERVICE_WATCHDOG}} + +[Install] +WantedBy=machines.target diff --git a/units/user/systemd-vmspawn@.service.in b/units/user/systemd-vmspawn@.service.in new file mode 100644 index 00000000000..aeea839f8c4 --- /dev/null +++ b/units/user/systemd-vmspawn@.service.in @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +[Unit] +Description=Virtual Machine %i +Documentation=man:systemd-vmspawn(1) +PartOf=machines.target +Before=machines.target + +[Service] +ExecStart=systemd-vmspawn --quiet --keep-unit --register=yes --network-tap --machine=%i +KillMode=mixed +Type=notify +Slice=machine.slice +{{SERVICE_WATCHDOG}} + +[Install] +WantedBy=machines.target