]> git.proxmox.com Git - pve-container.git/commitdiff
poststop: use a reboot trigger file
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 10 Mar 2017 10:25:41 +0000 (11:25 +0100)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 10 Mar 2017 12:49:51 +0000 (13:49 +0100)
Since the STOPPED state is set before cgroup cleanup we need
a better way to restart a container: We now install an
ExecStopPost snippet into the lxc@.service which when
encountering a reboot trigger file
(/var/lib/lxc/$vmid/reboot) performs a systemctl restart.

debian/triggers
src/Makefile
src/lxc-pve-poststop-hook
src/lxc-pve-prestart-hook
src/lxc-pve-reboot-trigger [new file with mode: 0755]
src/pve-reboot.conf [new file with mode: 0644]

index 59dd6885a5f9b5bb50a5278b557af628ddfa781f..b469b7261b67a08d6bb7a640aec2a051c1b37ed4 100644 (file)
@@ -1 +1,2 @@
 activate-noawait pve-api-updates
+activate-noawait /etc/init.d
index 7ffb593d1b1fb6298bc396d78a37f6dbdcf263bf..928db5ec77e20375acc9787614e8e230601fafa6 100644 (file)
@@ -2,6 +2,7 @@ PACKAGE=pve-container
 
 PREFIX=${DESTDIR}/usr
 BINDIR=${PREFIX}/bin
+LIBDIR=${PREFIX}/lib
 SBINDIR=${PREFIX}/sbin
 MANDIR=${PREFIX}/share/man
 DOCDIR=${PREFIX}/share/doc/${PACKAGE}
@@ -9,6 +10,7 @@ LXC_SCRIPT_DIR=${PREFIX}/share/lxc
 LXC_TMPL_DIR=${LXC_SCRIPT_DIR}/templates
 LXC_HOOK_DIR=${LXC_SCRIPT_DIR}/hooks
 LXC_COMMON_CONFIG_DIR=${LXC_SCRIPT_DIR}/config/common.conf.d
+SERVICEDIR=$(LIBDIR)/systemd/system
 PODDIR=${DOCDIR}/pod
 MAN1DIR=${MANDIR}/man1/
 MAN5DIR=${MANDIR}/man5/
@@ -33,6 +35,9 @@ install: pct lxc-pve.conf lxc-pve-prestart-hook lxc-pve-autodev-hook lxc-pve-pos
        install -m 0755 pve-update-lxc-config ${SBINDIR}
        install -d ${LXC_SCRIPT_DIR}
        install -m 0755 lxcnetaddbr ${LXC_SCRIPT_DIR}
+       install -m 0755 lxc-pve-reboot-trigger ${LXC_SCRIPT_DIR}
+       install -d -m0755 ${SERVICEDIR}/lxc@.service.d
+       install -m0644 pve-reboot.conf ${SERVICEDIR}/lxc@.service.d/
        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}
index a4302d6bbf13f3efc4cbd01c79d2032c9063d0d5..0396739e1584c24af98c480e96c6af92325b71f7 100755 (executable)
@@ -81,9 +81,12 @@ __PACKAGE__->register_method ({
            # that we must not block because we're part of the service cgroup
            # systemd waits for to die before issuing the new lxc-start command.
            PVE::LXC::update_lxc_config($vmid, $conf);
-           PVE::Tools::run_command(['systemctl', '--no-block', 'restart', "lxc\@$vmid"]);
+           # Tell the post-stop hook we want to be restarted.
+           open(my $fh, '>', "/var/lib/lxc/$vmid/reboot")
+               or die "failed to create reboot trigger file: $!\n";
+           close($fh);
            # cause lxc to stop instead of rebooting
-           POSIX::_exit(1);
+           exit(1);
        }
 
        return undef;
index 9835b1c6e8f958953a751988383706e5f44ad856..fd2942323b565ae3a94a7447964a5c5e41faf49d 100755 (executable)
@@ -76,6 +76,9 @@ __PACKAGE__->register_method ({
 
        my $rootdir = $param->{rootfs};
 
+       # Delete any leftover reboot-trigger file
+       unlink("/var/lib/lxc/$vmid/reboot");
+
        my $devlist_file = "/var/lib/lxc/$vmid/devices";
        unlink $devlist_file;
        my $devices = [];
diff --git a/src/lxc-pve-reboot-trigger b/src/lxc-pve-reboot-trigger
new file mode 100755 (executable)
index 0000000..95c3ac8
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my $vmid = $ARGV[0] or exit(1);
+exit(0) if $vmid !~ /^\d+$/; # check for a PVE ID
+exit(0) if !-e "/etc/pve/lxc/${vmid}.conf";
+exit(0) if !unlink("/var/lib/lxc/$vmid/reboot");
+exec {'systemctl'} 'systemctl', '--no-block', 'restart', "lxc\@${vmid}.service";
diff --git a/src/pve-reboot.conf b/src/pve-reboot.conf
new file mode 100644 (file)
index 0000000..8a0539c
--- /dev/null
@@ -0,0 +1,2 @@
+[Service]
+ExecStopPost=/usr/share/lxc/lxc-pve-reboot-trigger %i