--- recepies/lxc/lxc-watchdog.sh 2010/03/16 15:06:30 178 +++ recepies/lxc/lxc-watchdog.sh 2010/03/16 15:33:30 179 @@ -16,12 +16,40 @@ 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 + + +if [ "$2" == "stop" ] ; then + echo "$name stop" + kill -SIGPWR `head -1 /cgroup/$name/tasks` + lxc-wait -n $name -s STOPPED + exit +fi + -lxc-info -n $name | grep RUNNING || lxc-start -d -n $name -o /tmp/${name}.log && echo "$name start" +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...