]> git.proxmox.com Git - mirror_lxc.git/blob - config/init/common/lxc-containers.in
bebbbfaf477d0c9a2ffcd46ec65ad0246d80227c
[mirror_lxc.git] / config / init / common / lxc-containers.in
1 #!/bin/sh
2
3 sysconfdir="@SYSCONFDIR@"
4 distrosysconfdir="@LXC_DISTRO_SYSCONF@"
5 bindir="@BINDIR@"
6 localstatedir="@LOCALSTATEDIR@"
7
8 # These can be overridden in @LXC_DISTRO_SYSCONF@/lxc
9
10 # Autostart containers?
11 LXC_AUTO="true"
12
13 # BOOTGROUPS - What groups should start on bootup?
14 # Comma separated list of groups.
15 # Leading comma, trailing comma or embedded double
16 # comma indicates when the NULL group should be run.
17 # Example (default): boot the onboot group first then the NULL group
18 BOOTGROUPS="onboot,"
19
20 # SHUTDOWNDELAY - Wait time for a container to shut down.
21 # Container shutdown can result in lengthy system
22 # shutdown times. Even 5 seconds per container can be
23 # too long.
24 SHUTDOWNDELAY=5
25
26 # OPTIONS can be used for anything else.
27 # If you want to boot everything then
28 # options can be "-a" or "-a -A".
29 OPTIONS=
30
31 # STOPOPTS are stop options. The can be used for anything else to stop.
32 # If you want to kill containers fast, use -k
33 STOPOPTS="-a -A -s"
34
35 if [ -d "$localstatedir"/lock/subsys ]
36 then
37 lockdir="$localstatedir"/lock/subsys
38 else
39 lockdir="$localstatedir"/lock
40 fi
41
42 # Source any configurable options
43 [ ! -f "$distrosysconfdir"/lxc ] || . "$distrosysconfdir"/lxc
44
45 # Check for needed utility program
46 [ -x "$bindir"/lxc-autostart ] || exit 1
47
48 # If libvirtd is providing the bridge, it might not be
49 # immediately available, so wait a bit for it before starting
50 # up the containers or else any that use the bridge will fail
51 # to start
52 wait_for_bridge()
53 {
54 [ "x$USE_LXC_BRIDGE" = "xtrue" ] || { return 0; }
55
56 local BRNAME try flags br
57 [ -f "$sysconfdir"/lxc/default.conf ] || { return 0; }
58
59 BRNAME=`grep '^[ ]*lxc.net.0.link' "$sysconfdir"/lxc/default.conf | sed 's/^.*=[ ]*//'`
60 if [ -z "$BRNAME" ]; then
61 return 0
62 fi
63
64 for try in `seq 1 30`; do
65 for br in ${BRNAME}; do
66 [ -r /sys/class/net/${br}/flags ] || { sleep 1; continue 2; }
67 read flags < /sys/class/net/${br}/flags
68 [ $((flags & 0x1)) -eq 1 ] || { sleep 1; continue 2; }
69 done
70 return 0
71 done
72 }
73
74 # See how we were called.
75 case "$1" in
76 start)
77 [ "x$LXC_AUTO" = "xtrue" ] || { exit 0; }
78
79 [ ! -f "$lockdir"/lxc ] || { exit 0; }
80
81 if [ -n "$BOOTGROUPS" ]; then
82 BOOTGROUPS="-g $BOOTGROUPS"
83 fi
84 touch "$lockdir"/lxc
85 # Start containers
86 wait_for_bridge
87
88 # Start autoboot containers first then the NULL group "onboot,".
89 "$bindir"/lxc-autostart $OPTIONS $BOOTGROUPS
90 rm -f "$lockdir"/lxc
91 ;;
92
93 stop)
94 if [ -n "$SHUTDOWNDELAY" ]; then
95 SHUTDOWNDELAY="-t $SHUTDOWNDELAY"
96 fi
97
98 # The stop is serialized and can take excessive time. We need to avoid
99 # delaying the system shutdown / reboot as much as we can since it's not
100 # parallelized... Even 5 second timout may be too long.
101 "$bindir"/lxc-autostart $STOPOPTS $SHUTDOWNDELAY
102 ;;
103
104 restart|reload|force-reload)
105 $0 stop
106 $0 start
107 ;;
108
109 *)
110 echo "Usage: $0 {start|stop|restart|reload|force-reload}"
111 exit 2
112 ;;
113 esac
114
115 exit $?