-
Notifications
You must be signed in to change notification settings - Fork 0
/
lxc
executable file
·156 lines (132 loc) · 2.7 KB
/
lxc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#! /bin/sh
#
# lxc: Starts all LXC containers
#
# chkconfig: 345 24 02
# description:
# processname: lxc-start
# config:
# See: http://lxc.teegra.net/ for the original idea
# See : http://blog.flameeyes.eu/2009/08/08/linux-containers-and-the-init-scripts-problem for the auto stopping
# Source function library.
. /etc/init.d/functions
. /etc/sysconfig/network
LOCKFILE=/var/lock/subsys/lxc
TOOLS_PREFIX=/usr/bin
[ ! -f /etc/lxc.conf ] && exit 1
[ -f /etc/lxc.conf ] && source /etc/lxc.conf
base=${0##*/}
start() {
# Check that networking is configured.
[ ${NETWORKING} = "no" ] && exit 1
echo $"Starting LXC containers... "
for container in "${CONTAINERS[@]}"; do
if [ "${container}" = "${container#!}" ]; then
echo -n $"Starting Linux container: "
echo -n ${container}
/usr/bin/lxc-start-vm -n ${container}
RETVAL=$?
if [ $RETVAL = 0 ]; then
touch $LOCKFILE
success $"$base startup"
else
failure $"$base startup"
fi
echo
fi
done
return $RETVAL
}
force_stop() {
echc $"Forcing shutting down of LXC containers: "
for container in "${CONTAINERS[@]}"; do
if [ "${container}" = "${container#!}" ]; then
echo -n $"Stopping Linux container: "
echo -n ${container}
/usr/bin/lxc-stop -n ${container}
RETVAL=$?
[ $RETVAL = 0 ] && success $"$base shutdown" || failure $"$base shutdown"
echo
fi
done
rm -f $LOCKFILE
return $RETVAL
}
stop() {
echo $"Shutting down LXC containers: "
typeset -i PID=0
lxc-ps -C init -opid |while read container PID ;do
[[ $PID -gt 1 ]] || continue
echo -n $"Stopping Linux container: "
echo -n ${container}
/usr/bin/lxc-stop-vm -n ${container}
RETVAL=$?
[ $RETVAL = 0 ] && success $"$base shutdown" || failure $"$base shutdown"
echo
done
rm -f $LOCKFILE
return $RETVAL
}
restart() {
stop
start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
echo "Checking for LXC "
${TOOLS_PREFIX}/lxc-status-all 2>&1
RETVAL=$?
echo_success
echo
return $RETVAL
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
RETVAL=0
# See how we were called.
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
force-stop)
force_stop
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
condrestart)
if [ -f $LOCKFILE ]; then
restart
fi
;;
*)
echo $"Usage: $0 {start|stop|force-stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
;;
esac
exit $RETVAL