]> git.proxmox.com Git - pve-container.git/commitdiff
add new pve-container units
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 11 Oct 2017 12:13:11 +0000 (14:13 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 13 Oct 2017 11:16:31 +0000 (13:16 +0200)
to replace lxc@.service.

we want our unit to only start when manually invoked (by our code), and
stop on shutdown via pve-guests or pve-ha-lrm. lxc@ units are stopped by
systemd on shutdown, because of transitive dependencies.

since all instances of template service units are by default assigned to
a new slice with DefaultDependencies=yes, we also need to introduce our
own custom slice with DefaultDependencies=no.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
src/Makefile
src/pve-container-stop-wrapper [new file with mode: 0755]
src/pve-container@.service [new file with mode: 0644]
src/system-pve\x2dcontainer.slice [new file with mode: 0644]

index 9c5fbc389a215e12291f109b18ed5fd21d44e28f..f69dda2f34eb2ac2dcaf3fe91cf83cb96a1ba95a 100644 (file)
@@ -40,8 +40,11 @@ install: pct lxc-pve.conf lxc-pve-prestart-hook lxc-pve-autodev-hook lxc-pve-pos
        install -d ${LXC_SCRIPT_DIR}
        install -m 0755 lxcnetaddbr ${LXC_SCRIPT_DIR}
        install -m 0755 lxc-pve-reboot-trigger ${LXC_SCRIPT_DIR}
+       install -m 0755 pve-container-stop-wrapper ${LXC_SCRIPT_DIR}
        install -d -m0755 ${SERVICEDIR}/lxc@.service.d
        install -m0644 pve-reboot.conf ${SERVICEDIR}/lxc@.service.d/
+       install -m0644 pve-container@.service ${SERVICEDIR}/
+       install -m0644 'system-pve\x2dcontainer.slice' ${SERVICEDIR}/
        install -d ${LXC_HOOK_DIR}
        install -m 0755 lxc-pve-prestart-hook ${LXC_HOOK_DIR}
        install -m 0755 lxc-pve-autodev-hook ${LXC_HOOK_DIR}
diff --git a/src/pve-container-stop-wrapper b/src/pve-container-stop-wrapper
new file mode 100755 (executable)
index 0000000..97eafe5
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# sanity checks
+my $vmid = $ARGV[0] or exit(1);
+exit(0) if $vmid !~ /^\d+$/;
+exit(0) if !-e "/etc/pve/lxc/${vmid}.conf";
+
+if (unlink("/var/lib/lxc/$vmid/reboot")) {
+    # restart if rebooted from within container
+    exec {'systemctl'} 'systemctl', '--no-block', 'restart', "pve-container\@${vmid}.service";
+} elsif (!defined($ENV{EXIT_CODE}) || $ENV{EXIT_CODE} ne "exited") {
+    # stop if called via "systemctl stop lxc@ID"
+    exec {'lxc-stop'} 'lxc-stop', '-n', $vmid;
+} else {
+    # just exit if container was shutdown from within or via lxc-stop
+    exit(0);
+}
diff --git a/src/pve-container@.service b/src/pve-container@.service
new file mode 100644 (file)
index 0000000..fb4a069
--- /dev/null
@@ -0,0 +1,18 @@
+# based on lxc@.service, but without any dependencies because
+# starting and stopping should be initiated by PVE code, not
+# systemd.
+[Unit]
+Description=PVE LXC Container: %i
+DefaultDependencies=No
+Documentation=man:lxc-start man:lxc man:pct
+
+[Service]
+Type=forking
+KillMode=mixed
+TimeoutStopSec=120s
+ExecStart=/usr/bin/lxc-start -n %i
+ExecStop=/usr/share/lxc/pve-container-stop-wrapper %i
+# Environment=BOOTUP=serial
+# Environment=CONSOLETYPE=serial
+StandardOutput=syslog
+StandardError=syslog
diff --git a/src/system-pve\x2dcontainer.slice b/src/system-pve\x2dcontainer.slice
new file mode 100644 (file)
index 0000000..7edae2c
--- /dev/null
@@ -0,0 +1,9 @@
+# needed because instances of template service units automatically
+# get their own slice with DefaultDependencies=yes, regardless of
+# the DefaultDependencies value of the template unit
+#
+# see man systemd.service and pve-container@.service
+[Unit]
+Description=PVE LXC Container Slice
+DefaultDependencies=No
+Documentation=man:pct