/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 177 - (show annotations)
Tue Mar 16 14:52:56 2010 UTC (14 years, 1 month ago) by dpavlin
File MIME type: application/x-sh
File size: 1236 byte(s)
make container name first argument

1 #!/bin/bash
2
3 # based on Tony Risinger code from lxc-users
4 # http://www.mail-archive.com/lxc-users@lists.sourceforge.net/msg00074.html
5
6 which inotifywait >/dev/null || apt-get install inotify-tools
7
8 name=$1
9
10 if [ ! -e /var/lib/lxc/$name/config ] ; then
11 echo "Usage: $0 name"
12 ls /var/lib/lxc/*/config | cut -d/ -f5
13 exit 1
14 fi
15
16 rootfs=`grep lxc.rootfs /var/lib/lxc/$name/config | cut -d= -f2`
17 echo "$name rootfs $rootfs"
18
19 lxc-info -n $name | grep RUNNING || lxc-start -d -n $name -o /tmp/${name}.log && echo "$name start"
20
21 while true; do
22 # time of 5 minutes on it JUST IN CASE...
23 vps_utmp=${rootfs}/var/run/utmp
24 inotifywait -qqt 300 ${vps_utmp}
25 if [ $(wc -l < /cgroup/${name}/tasks) -eq 1 ]; then
26
27 runlevel="$(runlevel ${vps_utmp})"
28 echo "# $name runlevel $runlevel"
29
30 case $runlevel in
31 N*)
32 # nothing for new boot state
33 ;;
34 ??0)
35 echo "$name halt"
36 lxc-stop -n "${name}"
37 break
38 ;;
39 ??6)
40 echo "$name reboot";
41 lxc-stop -n ${name}
42 lxc-wait -n ${name} -s STOPPED
43 mount /mnt/llin -o remount,rw
44 lxc-start -d -n ${name} -o /tmp/${name}.log
45 ;;
46 *)
47 # make sure vps is still running
48 state="$(lxc-info -n "${name}" | sed -e 's/.* is //')"
49 [ "$state" = "RUNNING" ] || break
50 ;;
51 esac
52 fi
53 done
54

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26