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
46 # Source function library.
47 test ! -r "$sysconfdir"/rc.d/init.d/functions ||
48 . "$sysconfdir"/rc.d/init.d/functions
50 # Source any configurable options
51 test ! -r "$sysconfdir"/sysconfig/lxc ||
52 . "$sysconfdir"/sysconfig/lxc
54 # Check for needed utility program
55 [ -x "$bindir"/lxc-autostart ] || exit 1
57 # If libvirtd is providing the bridge, it might not be
58 # immediately available, so wait a bit for it before starting
59 # up the containers or else any that use the bridge will fail
63 [ -f "$sysconfdir"/lxc/default.conf ] || { return 0; }
65 which ifconfig >/dev/null 2>&1
69 which ip >/dev/null 2>&1
74 [ -n cmd ] || { return 0; }
76 BRNAME=`grep '^[ ]*lxc.network.link' "$sysconfdir"/lxc/default.conf | sed 's/^.*=[ ]*//'`
77 if [ -z "$BRNAME" ]; then
81 for try in `seq 1 30`; do
82 eval $cmd |grep "^$BRNAME" >/dev/null 2>&1
90 # See how we were called.
93 [ ! -f "$localstatedir"/lock/subsys/lxc ] || { exit 0; }
95 if [ -n "$BOOTGROUPS" ]
97 BOOTGROUPS="-g $BOOTGROUPS"
102 # Start autoboot containers first then the NULL group "onboot,".
103 ## action $"Starting LXC autoboot containers: " /usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS
105 ## echo "DEBUG: Launch: /usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS"
106 CONTAINERS_LIST=`/usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS --list`
107 ## CONTAINERS_LIST=`/usr/bin/lxc-autostart --list`
108 ## echo "DEBUG: CONTAINERS_LIST:$CONTAINERS_LIST"
110 run_cmd "Starting LXC containers ( $CONTAINERS_LIST ) from groups: $BOOTGROUPS " /usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS
112 touch "$localstatedir"/lock/subsys/lxc
115 if [ -n "$SHUTDOWNDELAY" ]
117 SHUTDOWNDELAY="-t $SHUTDOWNDELAY"
120 # The stop is serialized and can take excessive time. We need to avoid
121 # delaying the system shutdown / reboot as much as we can since it's not
122 # parallelized... Even 5 second timout may be too long.
123 ## action $"Stopping LXC containers: " "$bindir"/lxc-autostart $STOPOPTS $SHUTDOWNDELAY
124 CONTAINERS_LIST=`/usr/bin/lxc-autostart $STOPOPTS --list`
126 ## run_cmd "Stopping LXC containsers (CONTAINERS_LIST) from groups BOOTGROUPS " "$bindir"/lxc-autostart $STOPOPTS $SHUTDOWNDELAY
127 run_cmd "Stopping running LXC containers ($CONTAINERS_LIST) " "$bindir"/lxc-autostart $STOPOPTS $SHUTDOWNDELAY
129 rm -f "$localstatedir"/lock/subsys/lxc
131 restart|reload|force-reload)
136 lxc-ls --fancy # NOTE: python3-lxc is needed for lxc-ls
139 echo $"Usage: $0 {start|stop|restart|reload|force-reload}"