]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Additional logic for dealing with container shutdown / reboot
authorMichael H. Warfield <mhw@WittsEnd.com>
Sat, 28 Dec 2013 17:35:05 +0000 (12:35 -0500)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 2 Jan 2014 16:11:34 +0000 (10:11 -0600)
Additional logic for dealing with container shutdown / reboot

Fix a problem with CentOS containers and legacy Fedora (<16) containers
not shutting down or rebooting properly.  Copy /etc/init.d/halt to
/etc/init.d/lxc-halt, deleting everything from the "hwclock save" and
all after and append a force halt or reboot at the end of the new
script, to prevent reexecing init.  Link that script in as
S00lxc-halt in rc0.d and S00lxc-reboot in rc6.d to intercept the
shutdown process before it gets to S01halt / S01reboot causing the hang.

Fixed some typos in the CentOS template that were introduced in the
previous patch for hwaddr settings and missed in regression testing.

Cleaned up some instruction typos and tabs from previous patch.

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
templates/lxc-centos.in
templates/lxc-fedora.in

index 7d47715d0b9cb586c92b9afcada098930c3a2f54..3126bba1b7a5d0bf555d736428a51dc99c3a3233 100644 (file)
@@ -177,7 +177,35 @@ configure_centos()
         )
     fi
 
-   # configure the network using the dhcp
+    # Deal with some dain bramage in the /etc/init.d/halt script.
+    # Trim it and make it our own and link it in before the default
+    # halt script so we can intercept it.  This also preventions package
+    # updates from interferring with our interferring with it.
+    #
+    # There's generally not much in the halt script that useful but what's
+    # in there from resetting the hardware clock down is generally very bad.
+    # So we just eliminate the whole bottom half of that script in making
+    # ourselves a copy.  That way a major update to the init scripts won't
+    # trash what we've set up.
+    if [ -f ${rootfs_path}/etc/init.d/halt ]
+    then
+        sed -e '/hwclock/,$d' \
+            < ${rootfs_path}/etc/init.d/halt \
+            > ${rootfs_path}/etc/init.d/lxc-halt
+
+        echo '$command -f' >> ${rootfs_path}/etc/init.d/lxc-halt
+        chmod 755 ${rootfs_path}/etc/init.d/lxc-halt
+
+        # Link them into the rc directories...
+        (
+             cd ${rootfs_path}/etc/rc.d/rc0.d
+             ln -s ../init.d/lxc-halt S00lxc-halt
+             cd ${rootfs_path}/etc/rc.d/rc6.d
+             ln -s ../init.d/lxc-halt S00lxc-reboot
+        )
+    fi
+
+    # configure the network using the dhcp
     cat <<EOF > ${rootfs_path}/etc/sysconfig/network-scripts/ifcfg-eth0
 DEVICE=eth0
 BOOTPROTO=dhcp
index 5f66ff1ceca9508920719123f1b645f440e81e8b..8db93b32a3fd7e543ef4a8bf3327ca9de1eba63c 100644 (file)
@@ -143,6 +143,37 @@ configure_fedora()
         )
     fi
 
+    # Deal with some dain bramage in the /etc/init.d/halt script.
+    # Trim it and make it our own and link it in before the default
+    # halt script so we can intercept it.  This also preventions package
+    # updates from interferring with our interferring with it.
+    #
+    # There's generally not much in the halt script that useful but what's
+    # in there from resetting the hardware clock down is generally very bad.
+    # So we just eliminate the whole bottom half of that script in making
+    # ourselves a copy.  That way a major update to the init scripts won't
+    # trash what we've set up.
+    #
+    # This is mostly for legacy distros since any modern systemd Fedora
+    # release will not have this script so we won't try to intercept it.
+    if [ -f ${rootfs_path}/etc/init.d/halt ]
+    then
+        sed -e '/hwclock/,$d' \
+            < ${rootfs_path}/etc/init.d/halt \
+            > ${rootfs_path}/etc/init.d/lxc-halt
+
+        echo '$command -f' >> ${rootfs_path}/etc/init.d/lxc-halt
+        chmod 755 ${rootfs_path}/etc/init.d/lxc-halt
+
+        # Link them into the rc directories...
+        (
+             cd ${rootfs_path}/etc/rc.d/rc0.d
+             ln -s ../init.d/lxc-halt S00lxc-halt
+             cd ${rootfs_path}/etc/rc.d/rc6.d
+             ln -s ../init.d/lxc-halt S00lxc-reboot
+        )
+    fi
+
     # configure the network using the dhcp
     cat <<EOF > ${rootfs_path}/etc/sysconfig/network-scripts/ifcfg-eth0
 DEVICE=eth0