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
22 # These can be overridden in /etc/sysconfig/lxc
24 # BOOTGROUPS - What groups should start on bootup?
25 # Comma separated list of groups.
26 # Leading comma, trailing comma or embedded double
27 # comma indicates when the NULL group should be run.
28 # Example (default): boot the onboot group first then the NULL group
31 # SHUTDOWNDELAY - Wait time for a container to shut down.
32 # ner shutdown can result in lengthy system
33 # shutdown times. Even 5 seconds per container can be
37 # OPTIONS can be used for anything else.
38 # If you want to boot everything then
39 # options can be "-a" or "-a -A".
42 # STOPOPTS are stop options. The can be used for anything else to stop.
43 # If you want to kill containers fast, use -k
44 # --all list all auto-started containers (ignore groups)
45 # --shutdown shutdown the containers instead of starting them
46 STOPOPTS="--all --shutdown"
48 # Source function library.
49 test ! -r "$sysconfdir"/rc.d/init.d/functions ||
50 . "$sysconfdir"/rc.d/init.d/functions
52 # Source any configurable options
53 test ! -r "$sysconfdir"/sysconfig/lxc ||
54 . "$sysconfdir"/sysconfig/lxc
56 # Check for needed utility program
57 [ -x "$bindir"/lxc-autostart ] || exit 1
59 # If libvirtd is providing the bridge, it might not be
60 # immediately available, so wait a bit for it before starting
61 # up the containers or else any that use the bridge will fail
65 [ -f "$sysconfdir"/lxc/default.conf ] || { return 0; }
67 which ifconfig >/dev/null 2>&1
71 which ip >/dev/null 2>&1
76 [ -n cmd ] || { return 0; }
78 BRNAME=`grep '^[ ]*lxc.network.link' "$sysconfdir"/lxc/default.conf | sed 's/^.*=[ ]*//'`
79 if [ -z "$BRNAME" ]; then
83 for try in `seq 1 30`; do
84 eval $cmd |grep "^$BRNAME" >/dev/null 2>&1
92 # See how we were called.
95 [ ! -f "$localstatedir"/lock/subsys/lxc ] || { exit 0; }
97 if [ -n "$BOOTGROUPS" ]
99 BOOTGROUPS="-g $BOOTGROUPS"
103 CONTAINERS_LIST=`/usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS --list | tr '\n' ' '`
104 # echo "DEBUG: CONTAINERS_LIST=${CONTAINERS_LIST}"
105 run_cmd "$(nls "Starting LXC containers (%s) from groups: %s " "$CONTAINERS_LIST" "$BOOTGROUPS")" /usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS
106 touch "$localstatedir"/lock/subsys/lxc
109 if [ -n "$SHUTDOWNDELAY" ]
111 SHUTDOWNDELAY="-t $SHUTDOWNDELAY"
114 # The stop is serialized and can take excessive time. We need to avoid
115 # delaying the system shutdown / reboot as much as we can since it's not
116 # parallelized... Even 5 second timout may be too long.
117 CONTAINERS_LIST=`/usr/bin/lxc-autostart $STOPOPTS --list | tr '\n' ' '`
118 run_cmd "$(nls "Stopping running LXC containers (%s) " "$CONTAINERS_LIST")" /usr/bin/lxc-autostart $STOPOPTS $SHUTDOWNDELAY
119 rm -f "$localstatedir"/lock/subsys/lxc
121 restart|reload|force-reload)
126 lxc-ls --fancy --fancy-format name,state,pid,ipv4,ipv6,memory,ram,swap # NOTE: python3-lxc is needed for lxc-ls
129 echo $"Usage: $0 {start|stop|restart|reload|force-reload}"