16 |
# |
# |
17 |
# based on Tony Risinger post to lxc-users mailing list |
# based on Tony Risinger post to lxc-users mailing list |
18 |
# http://www.mail-archive.com/lxc-users@lists.sourceforge.net/msg00074.html |
# http://www.mail-archive.com/lxc-users@lists.sourceforge.net/msg00074.html |
19 |
|
# |
20 |
|
# Install with: |
21 |
|
# ln -sf /srv/sysadmin-cookbook/recepies/lxc/lxc-watchdog.sh /etc/init.d/lxc-watchdog |
22 |
|
# update-rc.d lxc-watchdog defaults |
23 |
|
|
24 |
|
|
25 |
which inotifywait >/dev/null || apt-get install inotify-tools |
which inotifywait >/dev/null || apt-get install inotify-tools |
37 |
|
|
38 |
|
|
39 |
lxc_rootfs() { |
lxc_rootfs() { |
40 |
grep lxc.rootfs "/var/lib/lxc/$1/config" | cut -d= -f2 | sed 's/^ *//' |
grep '^ *lxc\.rootfs *=' "/var/lib/lxc/$1/config" | cut -d= -f2 | sed 's/^ *//' |
41 |
} |
} |
42 |
|
|
43 |
|
|
164 |
} |
} |
165 |
|
|
166 |
|
|
167 |
|
usage() { |
168 |
|
echo "Usage: $0 {start|stop|restart|status|boot|disable} [name name ... ]" >&2 |
169 |
|
exit 3 |
170 |
|
} |
171 |
|
|
172 |
command_on_lxc() { |
command_on_lxc() { |
173 |
command=$1 |
command=$1 |
174 |
shift |
shift |
180 |
start) |
start) |
181 |
lxc_exists $1 |
lxc_exists $1 |
182 |
cleanup_init_scripts $1 |
cleanup_init_scripts $1 |
183 |
setup_inittab $1 ::power "p0::powerfail:/sbin/init 0" |
setup_inittab $1 ":respawn:/sbin/getty.*tty1" "c1:12345:respawn:/sbin/getty 38400 tty1 linux" |
184 |
setup_inittab $1 ::ctrlaltdel "p6::ctrlaltdel:/sbin/init 6" |
setup_inittab $1 "::power" "p0::powerfail:/sbin/init 0" |
185 |
|
setup_inittab $1 "::ctrlaltdel" "p6::ctrlaltdel:/sbin/init 6" |
186 |
lxc_start $1 |
lxc_start $1 |
187 |
# give container 5 seconds to start more than one process |
# give container 5 seconds to start more than one process |
188 |
( sleep 5 ; nohup $0 watchdog $1 >> /tmp/$1.log 2>/dev/null ) & |
( sleep 5 ; nohup $0 watchdog $1 >> /tmp/$1.log 2>/dev/null ) & |
204 |
echo -n > /var/lib/lxc/$1/on_boot |
echo -n > /var/lib/lxc/$1/on_boot |
205 |
;; |
;; |
206 |
*) |
*) |
207 |
echo "Usage: $0 {start|stop|restart|status}" >&2 |
usage |
|
exit 3 |
|
208 |
;; |
;; |
209 |
|
|
210 |
esac |
esac |
212 |
} |
} |
213 |
|
|
214 |
command=$1 |
command=$1 |
215 |
shift |
test -z "$command" && usage |
|
|
|
216 |
test "$command" = "status" && lxc_status && exit |
test "$command" = "status" && lxc_status && exit |
217 |
|
shift |
218 |
|
|
219 |
if [ -z "$1" ] ; then |
if [ -z "$1" ] ; then |
220 |
ls /var/lib/lxc/*/on_boot | while read path ; do |
ls /var/lib/lxc/*/on_boot | while read path ; do |