/[sysadmin-cookbook]/recepies/lxc/lxc-watchdog.sh
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /recepies/lxc/lxc-watchdog.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 245 by dpavlin, Tue Mar 29 18:02:44 2011 UTC revision 264 by root, Sun Jun 26 15:00:40 2011 UTC
# Line 145  lxc_start() { Line 145  lxc_start() {
145  lxc_watchdog() {  lxc_watchdog() {
146  name=$1  name=$1
147  rootfs=$(lxc_rootfs $1)  rootfs=$(lxc_rootfs $1)
148    run=$rootfs/var/run
149    test -L $run && run=$rootfs/`readlink $run` # recent Debian have symlink to /run
150    cd $run || echo "can't cd watchdog into $run"
151    
152  while true; do  while true; do
         vps_utmp=${rootfs}/var/run/utmp  
153          tasks=`wc -l < /cgroup/${name}/tasks`          tasks=`wc -l < /cgroup/${name}/tasks`
154          stop_on=1 # init          stop_on=1 # init
155          sulogins=`lxc-ps --name $name | grep sulogin | wc -l`          sulogins=`lxc-ps --name $name | grep sulogin | wc -l`
# Line 158  while true; do Line 160  while true; do
160          test -z "$tasks" && exit 1          test -z "$tasks" && exit 1
161          if [ "$tasks" -eq $stop_on ]; then          if [ "$tasks" -eq $stop_on ]; then
162    
163                  runlevel="$(runlevel ${vps_utmp})"                  runlevel="$(runlevel utmp)"
164                  lxc_log "$name runlevel $runlevel"                  lxc_log "$name runlevel $runlevel"
165    
166                  case $runlevel in                  case $runlevel in
167                  N*)                  N*)
168                          # nothing for new boot state                          # nothing for new boot state
169                  ;;                  ;;
170                  ??0)                  ??0|unknown)
171                          lxc_log "$name halt"                          lxc_log "$name halt"
172                          lxc-stop -n "${name}"                          lxc-stop -n "${name}"
173                          lxc-wait -n ${name} -s STOPPED                          lxc-wait -n ${name} -s STOPPED
# Line 188  while true; do Line 190  while true; do
190          fi          fi
191    
192          # time of 5 minutes on it JUST IN CASE...          # time of 5 minutes on it JUST IN CASE...
193          inotifywait -qqt 300 ${vps_utmp}          inotifywait -qqt 300 utmp
194  done  done
195    
196  lxc_log "$name watchdog exited"  lxc_log "$name watchdog exited"

Legend:
Removed from v.245  
changed lines
  Added in v.264

  ViewVC Help
Powered by ViewVC 1.1.26