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` |
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 |
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" |