updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / vzctl-git / openvz
blob14b151261dbefcf393b2a8e4610ee68d78bad0de
1 #!/bin/bash
3 # based on gentoo startup script from opnvz
6 . /etc/rc.conf
7 . /etc/rc.d/functions
9 VZ_MODULES="vzmon vzdev vzdquota"
10 VZ_NET_MODULES="vznetdev vzethdev"
11 VZ_MIGRATE_MODULES="vzcpt vzrst"
13 IP="/usr/sbin/ip"
14 MODPROBE="/sbin/modprobe"
15 SYSCTL="/sbin/sysctl"
17 VPSCONFDIR="/etc/vz/conf"
18 VZDEV=venet0
19 VZCTL="/usr/sbin/vzctl"
20 VZQUOTA="/usr/sbin/vzquota"
22 start_net() {
23 local mod
25 stat_busy "Setting up network for OpenVZ"
27 for mod in ${VZ_NET_MODULES}; do
28 ${MODPROBE} $mod 2> /dev/null
29 done
31 ${IP} link set ${VZDEV} up
32 ${IP} addr add 0.0.0.0/0 dev ${VZDEV}
33 ${SYSCTL} -q -w net.ipv4.conf.${VZDEV}.send_redirects=0
35 stat_done
38 stop_net() {
39 local mod
41 $IP link set ${VZDEV} down 2> /dev/null
43 for mod in ${VZ_NET_MODULES}; do
44 ${MODPROBE} -r $mod &> /dev/null
45 done
48 start_ve() {
49 local velist veid
51 cd ${VPSCONFDIR}
52 velist=$(grep -l '^ONBOOT=yes\|^ONBOOT=\"yes\"' [0-9]*.conf 2>/dev/null | sed -e 's/.conf//g' | sort -n)
53 cd - > /dev/null
55 ${SYSCTL} -q -w net.ipv4.route.src_check=0
57 for veid in ${velist}; do
58 stat_busy "Starting VE ${veid}"
60 ${VZCTL} start ${veid} &> /dev/null
62 if [ $? -gt 0 ]; then
63 stat_fail
64 else
65 stat_done
67 done
69 return 0
72 stop_ve() {
73 local veid velist
75 if [ ! -f /proc/vz/veinfo ]; then
76 return 0
79 velist=$(awk '$1 != 0 {print $1}' /proc/vz/veinfo | sort -nr)
81 for veid in ${velist}; do
82 stat_bkgd "Stopping VE ${veid}"
84 ${VZCTL} set ${veid} --cpuunits 2000 --cpulimit 0 &> /dev/null
85 ${VZCTL} stop ${veid} &> /dev/null &
86 done
88 # wait for ve's to stop
89 for veid in ${velist}; do
90 sleep 1
91 velist=$(awk '$1 != 0 {print $1}' /proc/vz/veinfo | sort -nr)
92 done
94 return 0
97 case "$1" in
98 start)
99 stat_busy "Loading OpenVZ modules"
101 if [ -e /dev/vzctl ]; then
102 echo "OpenVZ is already running."
103 stat_fail
104 exit 1
107 # Load modules
108 for mod in ${VZ_MODULES}; do
109 /sbin/modprobe -r $mod &> /dev/null
110 /sbin/modprobe $mod &> /dev/null
111 done
113 if [ ! -e /dev/vzctl ]; then
114 stat_fail
115 exit 1
118 for mod in ${VZ_MIGRATE_MODULES}; do
119 /sbin/modprobe -r $mod &> /dev/null
120 /sbin/modprobe $mod &> /dev/null
121 done
123 stat_done
125 start_net
126 start_ve
128 stat_busy "Starting OpenVZ"
129 add_daemon openvz
130 stat_done
132 stop)
133 stop_ve
134 # network modules removed here
135 stop_net
137 for mod in ${VZ_MIGRATE_MODULES} ${VZ_MODULES}; do
138 /sbin/modprobe -r $mod &> /dev/null
139 done
141 stat_busy "Stopping OpenVZ"
142 rm_daemon openvz
143 stat_done
145 restart)
146 $0 stop
147 sleep 1
148 $0 start
151 echo "usage: $0 {start|stop|restart}"
152 esac
153 exit 0