From 35607d232a8c1adc82498de910f84d20730d2b82 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 16 Mar 2010 15:33:30 +0000 Subject: [PATCH] add powerfail to container's /etc/inittab which halt on kill -SIGPWR git-svn-id: svn://svn.rot13.org/sysadmin-cookbook@179 191e9f34-6774-4a6d-acfc-7664dacd4a2a --- recepies/lxc/lxc-watchdog.sh | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/recepies/lxc/lxc-watchdog.sh b/recepies/lxc/lxc-watchdog.sh index 8c78e91..97ab178 100755 --- a/recepies/lxc/lxc-watchdog.sh +++ b/recepies/lxc/lxc-watchdog.sh @@ -16,12 +16,40 @@ fi rootfs=`grep lxc.rootfs /var/lib/lxc/$name/config | cut -d= -f2` echo "$name rootfs $rootfs" + # cleanup init scripts which don't work in containers -ls $rootfs/etc/rc?.d/*umountfs 2>/dev/null | xargs -i rm -v {} -ls $rootfs/etc/rc?.d/*umountroot 2>/dev/null | xargs -i rm -v {} -ls $rootfs/etc/rc?.d/*hwclock* 2>/dev/null | xargs -i rm -v {} +ls \ + $rootfs/etc/rc?.d/*umountfs \ + $rootfs/etc/rc?.d/*umountroot \ + $rootfs/etc/rc?.d/*hwclock* \ +2>/dev/null | xargs -i rm -v {} + + +# let container respond to kill -SIGPWR +inittab=$rootfs/etc/inittab +powerfail="pw::powerfail:/sbin/init 0" +if ! grep "$powerfail" ${inittab} >/dev/null ; then + grep -v ::power ${inittab} > ${inittab}.new + echo $powerfail >> ${inittab}.new + mv ${inittab}.new ${inittab} + echo "$initab modified" +fi + -lxc-info -n $name | grep RUNNING || lxc-start -d -n $name -o /tmp/${name}.log && echo "$name start" +if [ "$2" == "stop" ] ; then + echo "$name stop" + kill -SIGPWR `head -1 /cgroup/$name/tasks` + lxc-wait -n $name -s STOPPED + exit +fi + + +if ! lxc-info -n $name | grep RUNNING ; then + echo "$name start" + lxc-start -n $name -o /tmp/${name}.log -d + lxc-wait -n $name -s RUNNING + lxc-info -n $name +fi while true; do # time of 5 minutes on it JUST IN CASE... -- 2.20.1