]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
units: add units for vmspawn/nspawn in --user mode too
authorLennart Poettering <lennart@poettering.net>
Fri, 23 May 2025 13:41:58 +0000 (15:41 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 11 Jul 2025 16:17:04 +0000 (18:17 +0200)
units/machines.target
units/user/machine.slice [new file with mode: 0644]
units/user/machines.target [new file with mode: 0644]
units/user/meson.build
units/user/systemd-nspawn@.service.in [new file with mode: 0644]
units/user/systemd-vmspawn@.service.in [new file with mode: 0644]

index 165839aeb17fb1b68cafe192c081a1c3c81dfb9c..b7a84f481479c3769fea4e479766ebd2ee54846a 100644 (file)
@@ -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 (file)
index 0000000..fe729d0
--- /dev/null
@@ -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 (file)
index 0000000..35a9966
--- /dev/null
@@ -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
index c669e4bb1cb752f03482706e4439cacffe3d9d81..d8d3d9fdac57427024f1ba1b33fe750e6d9571a8 100644 (file)
@@ -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 (file)
index 0000000..90fdc0c
--- /dev/null
@@ -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 (file)
index 0000000..aeea839
--- /dev/null
@@ -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