]> git.pld-linux.org Git - packages/lxc.git/blame - lxc.init
Release 3. Fixes in init scripts.
[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
72d9317d
MK
44# --all list all auto-started containers (ignore groups)
45# --shutdown shutdown the containers instead of starting them
46STOPOPTS="--all --shutdown"
4a25e08f
MK
47
48# Source function library.
49test ! -r "$sysconfdir"/rc.d/init.d/functions ||
50 . "$sysconfdir"/rc.d/init.d/functions
51
52# Source any configurable options
53test ! -r "$sysconfdir"/sysconfig/lxc ||
54 . "$sysconfdir"/sysconfig/lxc
55
56# Check for needed utility program
57[ -x "$bindir"/lxc-autostart ] || exit 1
58
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
62# to start
63wait_for_bridge()
64{
65 [ -f "$sysconfdir"/lxc/default.conf ] || { return 0; }
66
67 which ifconfig >/dev/null 2>&1
68 if [ $? = 0 ]; then
69 cmd="ifconfig -a"
70 else
71 which ip >/dev/null 2>&1
72 if [ $? = 0 ]; then
73 cmd="ip link list"
74 fi
75 fi
76 [ -n cmd ] || { return 0; }
77
78 BRNAME=`grep '^[ ]*lxc.network.link' "$sysconfdir"/lxc/default.conf | sed 's/^.*=[ ]*//'`
79 if [ -z "$BRNAME" ]; then
80 return 0
81 fi
82
83 for try in `seq 1 30`; do
84 eval $cmd |grep "^$BRNAME" >/dev/null 2>&1
85 if [ $? = 0 ]; then
86 return
87 fi
88 sleep 1
89 done
90}
91
92# See how we were called.
93case "$1" in
94 start)
95 [ ! -f "$localstatedir"/lock/subsys/lxc ] || { exit 0; }
96
97 if [ -n "$BOOTGROUPS" ]
98 then
99 BOOTGROUPS="-g $BOOTGROUPS"
100 fi
101
102 # Start containers
72d9317d
MK
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
4a25e08f
MK
106 touch "$localstatedir"/lock/subsys/lxc
107 ;;
108 stop)
109 if [ -n "$SHUTDOWNDELAY" ]
110 then
111 SHUTDOWNDELAY="-t $SHUTDOWNDELAY"
112 fi
113
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.
72d9317d
MK
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
4a25e08f
MK
119 rm -f "$localstatedir"/lock/subsys/lxc
120 ;;
121 restart|reload|force-reload)
122 $0 stop
123 $0 start
124 ;;
125 status)
72d9317d 126 lxc-ls --fancy --fancy-format name,state,pid,ipv4,ipv6,memory,ram,swap # NOTE: python3-lxc is needed for lxc-ls
4a25e08f
MK
127 ;;
128 *)
129 echo $"Usage: $0 {start|stop|restart|reload|force-reload}"
130 exit 2
131esac
132exit $?
This page took 0.090952 seconds and 4 git commands to generate.