+lxc_log "$name watchdog exited"
+
+}
+
+
+usage() {
+ echo "Usage: $0 {start|stop|restart|status|boot|disable} [name name ... ]" >&2
+ exit 3
+}
+
+command_on_lxc() {
+command=$1
+shift
+
+echo "# $command $1"
+
+case "$command" in
+
+start)
+ lxc_exists $1
+ cleanup_init_scripts $1
+ setup_inittab $1 ":respawn:/sbin/getty.*tty1" "c1:12345:respawn:/sbin/getty 38400 tty1 linux"
+ setup_inittab $1 "::power" "p0::powerfail:/sbin/init 0"
+ setup_inittab $1 "::ctrlaltdel" "p6::ctrlaltdel:/sbin/init 6"
+ lxc_start $1
+ # give container 5 seconds to start more than one process
+ ( sleep 5 ; nohup $0 watchdog $1 >> /tmp/$1.log 2>/dev/null ) &
+ ;;
+stop|halt)
+ lxc_exists $1
+ lxc_stop $1
+ ;;
+reload|force-reload|restart|reboot)
+ lxc_kill $1 -SIGINT
+ ;;
+watchdog)
+ lxc_watchdog $1
+ ;;
+boot)
+ echo $1 > /var/lib/lxc/$1/on_boot
+ ;;
+disable)
+ echo -n > /var/lib/lxc/$1/on_boot
+ ;;
+*)
+ usage
+ ;;
+
+esac
+
+}
+
+command=$1
+test -z "$command" && usage
+test "$command" = "status" && lxc_status && exit
+shift
+
+if [ -z "$1" ] ; then
+ ls /var/lib/lxc/*/on_boot | while read path ; do
+ name=`echo $path | cut -d/ -f5`
+ if [ "$command" != "start" -o "$command" = "start" -a -s $path ] ; then
+ command_on_lxc $command $name
+ else
+ echo "# skip $command $name"
+ fi
+ done
+else
+ while [ ! -z "$1" ] ; do
+ command_on_lxc $command $1
+ shift
+ done
+fi
+