[lxc-devel] [PATCH 3/4] Support SIGPWR in Fedora and Centos containers.

Michael H. Warfield mhw at WittsEnd.com
Sat Mar 22 17:58:35 UTC 2014


Support SIGPWR in Fedora and Centos containers.

Added code to catch SIGPWR for Upstart in Fedora and CentOS
containers as well as for Systemd in Fedora containers.

Signed-off-by: Michael H. Warfield <mhw at WittsEnd.com>
---
 templates/lxc-centos.in | 12 ++++++++++++
 templates/lxc-fedora.in | 15 +++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/templates/lxc-centos.in b/templates/lxc-centos.in
index f11a98c..6d9e512 100644
--- a/templates/lxc-centos.in
+++ b/templates/lxc-centos.in
@@ -363,6 +363,18 @@ configure_centos_init()
         chroot ${rootfs_path} chkconfig udev-post off
     fi
     chroot ${rootfs_path} chkconfig network on
+
+    if [ -d ${rootfs_path}/etc/init ]
+    then
+       # This is to make upstart honor SIGPWR
+        cat <<EOF >${rootfs_path}/etc/init/power-status-changed.conf
+#  power-status-changed - shutdown on SIGPWR
+#
+start on power-status-changed
+    
+exec /sbin/shutdown -h now "SIGPWR received"
+EOF
+    fi
 }
 
 download_centos()
diff --git a/templates/lxc-fedora.in b/templates/lxc-fedora.in
index f32ca53..16f0c55 100644
--- a/templates/lxc-fedora.in
+++ b/templates/lxc-fedora.in
@@ -339,6 +339,19 @@ configure_fedora_init()
     sed -i 's/^.*dev.pts.*$/#\0/' ${rootfs_path}/etc/rc.d/rc.sysinit
     chroot ${rootfs_path} chkconfig udev-post off
     chroot ${rootfs_path} chkconfig network on
+
+    if [ -d ${rootfs_path}/etc/init ]
+    then
+       # This is to make upstart honor SIGPWR.  Should do no harm
+       # on systemd systems and some systems may have both.
+        cat <<EOF >${rootfs_path}/etc/init/power-status-changed.conf
+#  power-status-changed - shutdown on SIGPWR
+#
+start on power-status-changed
+    
+exec /sbin/shutdown -h now "SIGPWR received"
+EOF
+    fi
 }
 
 configure_fedora_systemd()
@@ -348,6 +361,8 @@ configure_fedora_systemd()
     chroot ${rootfs_path} ln -s /dev/null /etc/systemd/system/udev.service
     chroot ${rootfs_path} ln -s /dev/null /etc/systemd/system/systemd-journald.service
     chroot ${rootfs_path} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
+    # Make systemd honor SIGPWR
+    chroot ${rootfs_path} ln -s /usr/lib/systemd/system/halt.target /etc/systemd/system/
     #dependency on a device unit fails it specially that we disabled udev
     # sed -i 's/After=dev-%i.device/After=/' ${rootfs_path}/lib/systemd/system/getty\@.service
     #
-- 
1.8.3.1


-- 
Michael H. Warfield (AI4NB) | (770) 978-7061 |  mhw at WittsEnd.com
   /\/\|=mhw=|\/\/          | (678) 463-0932 |  http://www.wittsend.com/mhw/
   NIC whois: MHW9          | An optimist believes we live in the best of all
 PGP Key: 0x674627FF        | possible worlds.  A pessimist is sure of it!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 482 bytes
Desc: This is a digitally signed message part
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140322/b27bdee2/attachment.pgp>


More information about the lxc-devel mailing list