]>
Commit | Line | Data |
---|---|---|
015f0dd7 MW |
1 | #!/bin/sh |
2 | # | |
3 | # lxc Start/Stop LXC autoboot containers | |
4 | # | |
5 | # chkconfig: 345 99 01 | |
6 | # description: Starts/Stops all LXC containers configured for autostart. | |
7 | # | |
8 | ### BEGIN INIT INFO | |
9 | # Provides: lxc | |
10 | # Default-Start: 3 4 5 | |
11 | # Default-Stop: 0 1 6 | |
12 | # Short-Description: Bring up/down LXC autostart containers | |
13 | # Description: Bring up/down LXC autostart containers | |
14 | ### END INIT INFO | |
15 | ||
16 | sysconfdir="@SYSCONFDIR@" | |
17 | bindir="@BINDIR@" | |
18 | localstatedir="@LOCALSTATEDIR@" | |
19 | ||
20 | # These can be overridden in @SYSCONFDIR@/sysconfig/lxc | |
21 | ||
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 | |
27 | BOOTGROUPS="onboot," | |
28 | ||
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 | |
32 | # too long. | |
33 | SHUTDOWNDELAY=5 | |
34 | ||
35 | # OPTIONS can be used for anything else. | |
36 | # If you want to boot everything then | |
37 | # options can be "-a" or "-a -A". | |
38 | OPTIONS= | |
39 | ||
40 | # STOPOPTS are stop options. The can be used for anything else to stop. | |
41 | # If you want to kill containers fast, use -k | |
42 | STOPOPTS="-a -A -s" | |
43 | ||
44 | # Source function library. | |
45 | test ! -r "$sysconfdir"/rc.d/init.d/functions || | |
46 | . "$sysconfdir"/rc.d/init.d/functions | |
47 | ||
84b3775a MP |
48 | # provide action() fallback |
49 | if ! type action >/dev/null 2>&1; then | |
50 | action() { | |
51 | echo "$@" | |
52 | } | |
53 | fi | |
54 | ||
015f0dd7 MW |
55 | # Source any configurable options |
56 | test ! -r "$sysconfdir"/sysconfig/lxc || | |
57 | . "$sysconfdir"/sysconfig/lxc | |
58 | ||
59 | # Check for needed utility program | |
60 | [ -x "$bindir"/lxc-autostart ] || exit 1 | |
61 | ||
62 | # If libvirtd is providing the bridge, it might not be | |
63 | # immediately available, so wait a bit for it before starting | |
64 | # up the containers or else any that use the bridge will fail | |
65 | # to start | |
66 | wait_for_bridge() | |
67 | { | |
68 | [ -f "$sysconfdir"/lxc/default.conf ] || { return 0; } | |
69 | ||
70 | which ifconfig >/dev/null 2>&1 | |
71 | if [ $? = 0 ]; then | |
72 | cmd="ifconfig -a" | |
73 | else | |
74 | which ip >/dev/null 2>&1 | |
75 | if [ $? = 0 ]; then | |
76 | cmd="ip link list" | |
77 | fi | |
78 | fi | |
79 | [ -n cmd ] || { return 0; } | |
80 | ||
81 | BRNAME=`grep '^[ ]*lxc.network.link' "$sysconfdir"/lxc/default.conf | sed 's/^.*=[ ]*//'` | |
82 | if [ -z "$BRNAME" ]; then | |
83 | return 0 | |
84 | fi | |
85 | ||
86 | for try in `seq 1 30`; do | |
87 | eval $cmd |grep "^$BRNAME" >/dev/null 2>&1 | |
88 | if [ $? = 0 ]; then | |
89 | return | |
90 | fi | |
91 | sleep 1 | |
92 | done | |
93 | } | |
94 | ||
95 | # See how we were called. | |
96 | case "$1" in | |
97 | start) | |
98 | [ ! -f "$localstatedir"/lock/subsys/lxc ] || { exit 0; } | |
99 | ||
100 | if [ -n "$BOOTGROUPS" ] | |
101 | then | |
102 | BOOTGROUPS="-g $BOOTGROUPS" | |
103 | fi | |
104 | ||
105 | # Start containers | |
106 | wait_for_bridge | |
107 | # Start autoboot containers first then the NULL group "onboot,". | |
31098f8b | 108 | action $"Starting LXC autoboot containers: " "$bindir"/lxc-autostart $OPTIONS $BOOTGROUPS |
015f0dd7 MW |
109 | touch "$localstatedir"/lock/subsys/lxc |
110 | ;; | |
111 | stop) | |
112 | if [ -n "$SHUTDOWNDELAY" ] | |
113 | then | |
114 | SHUTDOWNDELAY="-t $SHUTDOWNDELAY" | |
115 | fi | |
116 | ||
117 | # The stop is serialized and can take excessive time. We need to avoid | |
118 | # delaying the system shutdown / reboot as much as we can since it's not | |
119 | # parallelized... Even 5 second timout may be too long. | |
120 | action $"Stopping LXC containers: " "$bindir"/lxc-autostart $STOPOPTS $SHUTDOWNDELAY | |
121 | rm -f "$localstatedir"/lock/subsys/lxc | |
122 | ;; | |
123 | restart|reload|force-reload) | |
124 | $0 stop | |
125 | $0 start | |
126 | ;; | |
127 | *) | |
31098f8b | 128 | echo "Usage: $0 {start|stop|restart|reload|force-reload}" |
015f0dd7 MW |
129 | exit 2 |
130 | esac | |
131 | exit $? |