]> git.pld-linux.org Git - packages/lxc.git/blame - lxc.init
- rel 1
[packages/lxc.git] / lxc.init
CommitLineData
4a25e08f
MK
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# set -x
17
18sysconfdir="/etc"
19bindir="/usr/bin"
20localstatedir="/var"
21
22# These can be overridden in /etc/sysconfig/lxc
23
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
29BOOTGROUPS="onboot,"
30
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
34# too long.
35SHUTDOWNDELAY=5
36
37# OPTIONS can be used for anything else.
38# If you want to boot everything then
39# options can be "-a" or "-a -A".
40OPTIONS=
41
42# STOPOPTS are stop options. The can be used for anything else to stop.
43# If you want to kill containers fast, use -k
44STOPOPTS="-a -s"
45
46# Source function library.
47test ! -r "$sysconfdir"/rc.d/init.d/functions ||
48 . "$sysconfdir"/rc.d/init.d/functions
49
50# Source any configurable options
51test ! -r "$sysconfdir"/sysconfig/lxc ||
52 . "$sysconfdir"/sysconfig/lxc
53
54# Check for needed utility program
55[ -x "$bindir"/lxc-autostart ] || exit 1
56
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
60# to start
61wait_for_bridge()
62{
63 [ -f "$sysconfdir"/lxc/default.conf ] || { return 0; }
64
65 which ifconfig >/dev/null 2>&1
66 if [ $? = 0 ]; then
67 cmd="ifconfig -a"
68 else
69 which ip >/dev/null 2>&1
70 if [ $? = 0 ]; then
71 cmd="ip link list"
72 fi
73 fi
74 [ -n cmd ] || { return 0; }
75
76 BRNAME=`grep '^[ ]*lxc.network.link' "$sysconfdir"/lxc/default.conf | sed 's/^.*=[ ]*//'`
77 if [ -z "$BRNAME" ]; then
78 return 0
79 fi
80
81 for try in `seq 1 30`; do
82 eval $cmd |grep "^$BRNAME" >/dev/null 2>&1
83 if [ $? = 0 ]; then
84 return
85 fi
86 sleep 1
87 done
88}
89
90# See how we were called.
91case "$1" in
92 start)
93 [ ! -f "$localstatedir"/lock/subsys/lxc ] || { exit 0; }
94
95 if [ -n "$BOOTGROUPS" ]
96 then
97 BOOTGROUPS="-g $BOOTGROUPS"
98 fi
99
100 # Start containers
101 ## wait_for_bridge
102 # Start autoboot containers first then the NULL group "onboot,".
103 ## action $"Starting LXC autoboot containers: " /usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS
104 ## msg_starting lxc
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"
109
110 run_cmd "Starting LXC containers ( $CONTAINERS_LIST ) from groups: $BOOTGROUPS " /usr/bin/lxc-autostart $OPTIONS $BOOTGROUPS
111
112 touch "$localstatedir"/lock/subsys/lxc
113 ;;
114 stop)
115 if [ -n "$SHUTDOWNDELAY" ]
116 then
117 SHUTDOWNDELAY="-t $SHUTDOWNDELAY"
118 fi
119
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`
125
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
128
129 rm -f "$localstatedir"/lock/subsys/lxc
130 ;;
131 restart|reload|force-reload)
132 $0 stop
133 $0 start
134 ;;
135 status)
136 lxc-ls --fancy # NOTE: python3-lxc is needed for lxc-ls
137 ;;
138 *)
139 echo $"Usage: $0 {start|stop|restart|reload|force-reload}"
140 exit 2
141esac
142exit $?
This page took 0.154934 seconds and 4 git commands to generate.