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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 178 - (hide annotations)
Tue Mar 16 15:06:30 2010 UTC (14 years, 1 month ago) by dpavlin
File MIME type: application/x-sh
File size: 1482 byte(s)
cleanup init scripts which are not needed inside containers

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26