/[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 188 by dpavlin, Tue Mar 16 22:00:20 2010 UTC revision 189 by dpavlin, Tue Mar 16 23:05:31 2010 UTC
# Line 39  lxc_rootfs() { Line 39  lxc_rootfs() {
39    
40  lxc_status() {  lxc_status() {
41          lxc-ls -1 | sort -u | xargs -i lxc-info -n {} | sed "s/'//g" | while read name is status ; do          lxc-ls -1 | sort -u | xargs -i lxc-info -n {} | sed "s/'//g" | while read name is status ; do
42                  on_boot="       "                  boot="    "
43                  test -s /var/lib/lxc/$name/on_boot && on_boot="on_boot"                  test -s /var/lib/lxc/$name/on_boot && boot="boot"
44                  echo "$name $status $on_boot $(lxc_rootfs $name)"                  echo "$name $status $boot $(lxc_rootfs $name)"
45          done          done
46  }  }
47    
# Line 73  setup_inittab() { Line 73  setup_inittab() {
73  }  }
74    
75    
76    lxc_log() {
77            echo `date +%Y-%m-%dT%H:%M:%S` $*
78    }
79    
80    
81  lxc_kill() {  lxc_kill() {
82          name=$1          name=$1
83          sig=$2          sig=$2
# Line 82  lxc_kill() { Line 87  lxc_kill() {
87                  lxc-info -n $name                  lxc-info -n $name
88                  exit 1                  exit 1
89          fi          fi
90          echo "$name kill $sig $init_pid"          lxc_log "$name kill $sig $init_pid"
91          /bin/kill $sig $init_pid          /bin/kill $sig $init_pid
92  }  }
93    
94  lxc_stop() {  lxc_stop() {
95            lxc_log "$name stop"
96          lxc_kill $name -SIGPWR          lxc_kill $name -SIGPWR
97          lxc-wait -n $name -s STOPPED          lxc-wait -n $name -s STOPPED
98            lxc_log "$name stoped"
99  #       rm -f /var/lib/lxc/${name}/on_boot  #       rm -f /var/lib/lxc/${name}/on_boot
100  }  }
101    
# Line 97  lxc_start() { Line 104  lxc_start() {
104          name=$1          name=$1
105    
106          if ! lxc-info -n $name | grep RUNNING ; then          if ! lxc-info -n $name | grep RUNNING ; then
107                  echo "$name start"                  lxc_log "$name start"
108                  lxc-start -n $name -o /tmp/${name}.log -d                  lxc-start -n $name -o /tmp/${name}.log -d
109                  lxc-wait  -n $name -s RUNNING                  lxc-wait  -n $name -s RUNNING
110                  lxc-info  -n $name                  lxc-info  -n $name
# Line 105  lxc_start() { Line 112  lxc_start() {
112          fi          fi
113  }  }
114    
 lxc_log() {  
         echo `date +%Y-%m-%dT%H:%M:%S` $*  
 }  
   
115  lxc_watchdog() {  lxc_watchdog() {
116  name=$1  name=$1
117  rootfs=$(lxc_rootfs $1)  rootfs=$(lxc_rootfs $1)
# Line 152  while true; do Line 155  while true; do
155          inotifywait -qqt 300 ${vps_utmp}          inotifywait -qqt 300 ${vps_utmp}
156  done  done
157    
158  lxc_log "$name exited"  lxc_log "$name watchdog exited"
159    
160  }  }
161    
# Line 200  esac Line 203  esac
203  }  }
204    
205  command=$1  command=$1
206    shift
207    
208  test "$command" = "status" && lxc_status && exit  test "$command" = "status" && lxc_status && exit
209    
210  if [ -z "$1" ] ; then  if [ -z "$1" ] ; then
211          ls /var/lib/lxc/*/on_boot | while read path ; do          ls /var/lib/lxc/*/on_boot | while read path ; do
212                  name=`echo $path | cut -d/ -f5`                  name=`echo $path | cut -d/ -f5`
213                  command_on_lxc $command $name                  if [ "$command" != "start" -o "$command" = "start" -a -s $path ] ; then
214                            command_on_lxc $command $name
215                    else
216                            echo "# skip $command $name"
217                    fi
218          done          done
219  else  else
         shift  
220          while [ ! -z "$1" ] ; do          while [ ! -z "$1" ] ; do
221                  command_on_lxc $command $1                  command_on_lxc $command $1
222                  shift                  shift

Legend:
Removed from v.188  
changed lines
  Added in v.189

  ViewVC Help
Powered by ViewVC 1.1.26