3 # lxc Start/Stop LXC autoboot containers
6 # description: Starts/Stops all LXC containers configured for autostart.
10 # Default-Start: 3 4 5
12 # Short-Description: Bring up/down LXC autostart containers
13 # Description: Bring up/down LXC autostart containers
16 sysconfdir
="@SYSCONFDIR@"
18 localstatedir
="@LOCALSTATEDIR@"
20 # These can be overridden in @SYSCONFDIR@/sysconfig/lxc
22 # BOOTGROUPS - What groups should start on bootup?
23 # Comma separated list of groups.
24 # Leading comma, trailing comma or embedded double
25 # comma indicates when the NULL group should be run.
26 # Example (default): boot the onboot group first then the NULL group
29 # SHUTDOWNDELAY - Wait time for a container to shut down.
30 # ner shutdown can result in lengthy system
31 # shutdown times. Even 5 seconds per container can be
35 # OPTIONS can be used for anything else.
36 # If you want to boot everything then
37 # options can be "-a" or "-a -A".
40 # STOPOPTS are stop options. The can be used for anything else to stop.
41 # If you want to kill containers fast, use -k
44 # Source function library.
45 test ! -r "$sysconfdir"/rc.d
/init.d
/functions ||
46 .
"$sysconfdir"/rc.d
/init.d
/functions
48 # Source any configurable options
49 test ! -r "$sysconfdir"/sysconfig
/lxc ||
50 .
"$sysconfdir"/sysconfig
/lxc
52 # Check for needed utility program
53 [ -x "$bindir"/lxc-autostart
] ||
exit 1
55 # If libvirtd is providing the bridge, it might not be
56 # immediately available, so wait a bit for it before starting
57 # up the containers or else any that use the bridge will fail
61 [ -f "$sysconfdir"/lxc
/default.conf
] ||
{ return 0; }
63 which ifconfig
>/dev
/null
2>&1
67 which ip
>/dev
/null
2>&1
72 [ -n cmd
] ||
{ return 0; }
74 BRNAME
=`grep '^[ ]*lxc.network.link' "$sysconfdir"/lxc/default.conf | sed 's/^.*=[ ]*//'`
75 if [ -z "$BRNAME" ]; then
79 for try
in `seq 1 30`; do
80 eval $cmd |
grep "^$BRNAME" >/dev
/null
2>&1
88 # See how we were called.
91 [ ! -f "$localstatedir"/lock
/subsys
/lxc
] ||
{ exit 0; }
93 if [ -n "$BOOTGROUPS" ]
95 BOOTGROUPS
="-g $BOOTGROUPS"
100 # Start autoboot containers first then the NULL group "onboot,".
101 action $
"Starting LXC autoboot containers: " /usr
/bin
/lxc-autostart
$OPTIONS $BOOTGROUPS
102 touch "$localstatedir"/lock
/subsys
/lxc
105 if [ -n "$SHUTDOWNDELAY" ]
107 SHUTDOWNDELAY
="-t $SHUTDOWNDELAY"
110 # The stop is serialized and can take excessive time. We need to avoid
111 # delaying the system shutdown / reboot as much as we can since it's not
112 # parallelized... Even 5 second timout may be too long.
113 action $
"Stopping LXC containers: " "$bindir"/lxc-autostart
$STOPOPTS $SHUTDOWNDELAY
114 rm -f "$localstatedir"/lock
/subsys
/lxc
116 restart|reload|force-reload
)
121 echo $
"Usage: $0 {start|stop|restart|reload|force-reload}"