[Lxc-users] container auto-restart after host reboot

Ulli Horlacher framstag at rus.uni-stuttgart.de
Mon May 23 23:03:59 UTC 2011


To have auto-restart of my containers after a host reboot I add a sticky
bit to their configuration file (indeed this does my lxc meta-script) and
on the host I have the init-script:

root at vms2:/lxc# cat /etc/init.d/lxc
#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          lxc
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: lxc sysv init script
# Description:       linux containers auto start/stop
### END INIT INFO
#

PATH=/root/bin:/opt/lxc-0.7.4.1/bin:$PATH

case "$1" in
  start)
    for c in /lxc/*.cfg; do
      test -k $c && lxc -b $c
    done
    ;;
  stop)
    for c in /lxc/*cfg; do
      c=$(basename $c .cfg)
      if [ -d /cgroup/$c ]; then
        lxc -st $c
      fi
    done
    ;;
  status)
    lxc -l
    ;;
  *)
    echo "Usage: /etc/init.d/lxc {start|stop|status}"
    exit 1
esac


This does the trick:

root at zoo:/lxc# lxc -l                                                  
container              disk (MB)    RAM (MB)   start-PID    status
bunny                        517           6        5334   running
ubuntu                       517           0           0   stopped

root at zoo:/lxc# reboot

Broadcast message from root at zoo
        (/dev/pts/0) at 17:58 ...

The system is going down for reboot NOW!
root at zoo:/lxc# Write failed: Broken pipe
root at obertux:~#
root at obertux:~# ssh zoo

root at zoo:~# lxc -l
container              disk (MB)    RAM (MB)   start-PID    status
bunny                        517           6        1229   running
ubuntu                       517           0           0   stopped


-- 
Ullrich Horlacher              Server- und Arbeitsplatzsysteme
Rechenzentrum                  E-Mail: horlacher at rus.uni-stuttgart.de
Universitaet Stuttgart         Tel:    ++49-711-685-65868
Allmandring 30                 Fax:    ++49-711-682357
70550 Stuttgart (Germany)      WWW:    http://www.rus.uni-stuttgart.de/




More information about the lxc-users mailing list