blob: 0690d70bdff528bc8f61b8be73d69869ebbe659e (
about) (
plain) (
blame)
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
|
#!/bin/sh
# rc.lxc init script
# Written by Matteo Bernardini <ponce@slackbuilds.org>
#
# This script checks for the presence of the parameter lxc.start.auto
# in the available container configurations: if it's set to 1 the
# container is started (in an auto-detached screen session if
# screen is available) when rc.lxc is called with the "start" param.
#
# To stop the container it uses lxc-attach to execute /sbin/halt
# inside of it.
. /usr/share/lxc/lxc.functions
start_lxc() {
for CONTAIN in $(/usr/bin/lxc-ls); do
if [ "$(lxc-info -n $CONTAIN -c lxc.start.auto)" = "lxc.start.auto = 1" ]; then
if [ "$(/usr/bin/lxc-info -s -n $CONTAIN | grep STOPPED$)" ]; then
echo "Starting LXC container ${CONTAIN}."
/usr/bin/lxc-start -n $CONTAIN
/usr/bin/lxc-wait -n $CONTAIN -s RUNNING
if [ $? -gt 0 ]; then
return 2
fi
fi
fi
done
}
stop_lxc() {
for CONTAIN in $(/usr/bin/lxc-ls --active); do
echo "Stopping LXC container ${CONTAIN}."
/usr/bin/lxc-stop -n $CONTAIN
/usr/bin/lxc-wait -n $CONTAIN -s STOPPED
if [ $? -gt 0 ]; then
return 2
fi
done
}
restart_lxc() {
stop_lxc
sleep 2
start_lxc
}
case "$1" in
'start')
start_lxc
;;
'stop')
stop_lxc
;;
restart)
restart_lxc
;;
*)
echo "usage $0 start|stop|restart"
esac
|