105 |
fi |
fi |
106 |
} |
} |
107 |
|
|
108 |
|
lxc_log() { |
109 |
|
echo `date +%Y-%m-%dT%H:%M:%S` $* |
110 |
|
} |
111 |
|
|
112 |
lxc_watchdog() { |
lxc_watchdog() { |
113 |
name=$1 |
name=$1 |
114 |
rootfs=$(lxc_rootfs $1) |
rootfs=$(lxc_rootfs $1) |
120 |
if [ "$tasks" -eq 1 ]; then |
if [ "$tasks" -eq 1 ]; then |
121 |
|
|
122 |
runlevel="$(runlevel ${vps_utmp})" |
runlevel="$(runlevel ${vps_utmp})" |
123 |
echo `date +%Y-%m-%dT%H:%M:%S` "$name runlevel $runlevel" |
lxc_log "$name runlevel $runlevel" |
124 |
|
|
125 |
case $runlevel in |
case $runlevel in |
126 |
N*) |
N*) |
127 |
# nothing for new boot state |
# nothing for new boot state |
128 |
;; |
;; |
129 |
??0) |
??0) |
130 |
echo "$name halt" |
lxc_log "$name halt" |
131 |
lxc-stop -n "${name}" |
lxc-stop -n "${name}" |
132 |
lxc-wait -n ${name} -s STOPPED |
lxc-wait -n ${name} -s STOPPED |
133 |
break |
break |
134 |
;; |
;; |
135 |
??6) |
??6) |
136 |
echo "$name reboot"; |
lxc_log "$name reboot"; |
137 |
lxc-stop -n ${name} |
lxc-stop -n ${name} |
138 |
lxc-wait -n ${name} -s STOPPED |
lxc-wait -n ${name} -s STOPPED |
139 |
lxc-start -d -n ${name} -o /tmp/${name}.log |
lxc-start -d -n ${name} -o /tmp/${name}.log |
145 |
;; |
;; |
146 |
esac |
esac |
147 |
else |
else |
148 |
echo "# $name $tasks tasks" |
lxc_log "$name $tasks tasks" |
149 |
fi |
fi |
150 |
|
|
151 |
# time of 5 minutes on it JUST IN CASE... |
# time of 5 minutes on it JUST IN CASE... |
152 |
inotifywait -qqt 300 ${vps_utmp} |
inotifywait -qqt 300 ${vps_utmp} |
153 |
done |
done |
154 |
|
|
155 |
echo "${name} exited" |
lxc_log "$name exited" |
156 |
|
|
157 |
} |
} |
158 |
|
|
171 |
setup_inittab $1 ::power "p0::powerfail:/sbin/init 0" |
setup_inittab $1 ::power "p0::powerfail:/sbin/init 0" |
172 |
setup_inittab $1 ::ctrlaltdel "p6::ctrlaltdel:/sbin/init 6" |
setup_inittab $1 ::ctrlaltdel "p6::ctrlaltdel:/sbin/init 6" |
173 |
lxc_start $1 |
lxc_start $1 |
174 |
( nohup $0 watchdog $1 >> /tmp/$1.log 2>/dev/null ) & |
# give container 5 seconds to start more than one process |
175 |
|
( sleep 5 ; nohup $0 watchdog $1 >> /tmp/$1.log 2>/dev/null ) & |
176 |
;; |
;; |
177 |
stop|halt) |
stop|halt) |
178 |
lxc_exists $1 |
lxc_exists $1 |
184 |
watchdog) |
watchdog) |
185 |
lxc_watchdog $1 |
lxc_watchdog $1 |
186 |
;; |
;; |
187 |
|
boot) |
188 |
|
echo $1 > /var/lib/lxc/$1/on_boot |
189 |
|
;; |
190 |
|
disable) |
191 |
|
echo -n > /var/lib/lxc/$1/on_boot |
192 |
|
;; |
193 |
*) |
*) |
194 |
echo "Usage: $0 {start|stop|restart|status}" >&2 |
echo "Usage: $0 {start|stop|restart|status}" >&2 |
195 |
exit 3 |
exit 3 |
200 |
} |
} |
201 |
|
|
202 |
command=$1 |
command=$1 |
|
shift |
|
203 |
|
|
204 |
test "$command" = "status" && lxc_status && exit |
test "$command" = "status" && lxc_status && exit |
205 |
|
|
209 |
command_on_lxc $command $name |
command_on_lxc $command $name |
210 |
done |
done |
211 |
else |
else |
212 |
|
shift |
213 |
while [ ! -z "$1" ] ; do |
while [ ! -z "$1" ] ; do |
214 |
command_on_lxc $command $1 |
command_on_lxc $command $1 |
215 |
shift |
shift |