1
0
mirror of https://github.com/systemd/systemd synced 2025-10-06 00:13:24 +02:00

units: add units for vmspawn/nspawn in --user mode too

This commit is contained in:
Lennart Poettering
2025-05-23 15:41:58 +02:00
parent 12d1f44681
commit 48cb009afc
6 changed files with 126 additions and 7 deletions

View 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

12
units/user/machine.slice Normal file
View File

@@ -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)

View File

@@ -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

View 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

View File

@@ -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

View File

@@ -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