/[vps]/vzctl/init.d/vz.initd
Gentoo

Contents of /vzctl/init.d/vz.initd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 96 - (show annotations) (download)
Wed Nov 23 21:55:54 2005 UTC (8 years, 9 months ago) by hollow
File size: 5465 byte(s)
add vzctl stuff
1 #!/sbin/runscript
2 # Copyright 1999-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo-x86/sys-cluster/vzctl/files/vz.initd,v 1.1 2005/09/26 15:32:35 hollow Exp $
5
6 depend() {
7 need net
8 before iptables
9 }
10
11 check_config() {
12 # if we don't want openvz running, say so
13 [ "${VIRTUOZZO}" = "yes" ] || return 1
14
15 # set default values
16 : ${VZCTL:=/usr/sbin/vzctl}
17 : ${VZQUOTA:=/usr/sbin/vzquota}
18 : ${VZVEINFO:=/proc/vz/veinfo}
19 : ${VPSCONFDIR:=/etc/vz}
20 : ${PRELOAD_MODULES:="af_packet"}
21 : ${MODULES:="vzmon vzdquota vzdev"}
22 : ${NET_MODULES="vznetdev vznet"}
23 : ${VZDEV:=venet0}
24 : ${PARALLEL:=4}
25
26 # check if you should load vzwdog module
27 [ "${VZWDOG}" = "yes" ] && MODULES="${MODULES} vzwdog"
28
29 # we need a working vzctl
30 if [ ! -x "${VZCTL}" ]; then
31 eerror "vzctl missing (${VZCTL})"
32 return 1
33 fi
34
35 # prevent dumb users from failure
36 if [ ! -e /dev/vzctl ]; then
37 eerror "Missing device node /dev/vzctl"
38 einfo
39 einfo "Please create the vzctl device node using the following command:"
40 einfo " /bin/mknod /dev/vzctl c 126 0"
41 einfo
42 return 1
43 fi
44
45 if [ -z "${VE0CPUUNITS}" ]; then
46 ewarn "VE0CPUUNITS is not set in /etc/conf.d/vz; using default value of 1000"
47 VE0CPUUNITS=1000
48 fi
49 return 0
50 }
51
52 start_net() {
53 local mod
54
55 # we don't operate on a running interface
56 if /sbin/ip addr ls | grep -q "venet0:.*UP" 2>/dev/null; then
57 return 0
58 fi
59
60 # load necessary modules
61 for mod in ${NET_MODULES}; do
62 /sbin/modprobe ${mod} 2>/dev/null
63 done
64
65 # configure the device
66 ebegin "Bringing up interface ${VZDEV}"
67 /sbin/ip link set ${VZDEV} up
68 eend $?
69
70 /sbin/ip addr add 0.0.0.0/0 dev ${VZDEV}
71
72 ebegin "Configuring interface ${VZDEV}"
73 /sbin/sysctl -q -w net.ipv4.conf.${VZDEV}.send_redirects=0
74 eend $?
75 }
76
77 stop_net() {
78 local mod
79
80 if /sbin/ip a l | grep -q "venet0:.*UP" 2>/dev/null; then
81 ebegin "Bringing down interface ${VZDEV}"
82 /sbin/ip link set ${VZDEV} down 2>/dev/null
83 eend $?
84 fi
85
86 # remove all modules we probably loaded on start_net
87 for mod in ${NET_MODULES}; do
88 /sbin/modprobe -r ${mod} > /dev/null 2>&1
89 done
90 }
91
92 start_ve() {
93 local veid velist msg need_restart=""
94
95 # get all VPSs we should start on boot
96 if ! cd ${VPSCONFDIR}; then
97 eerror $? "Unable to cd to ${VPSCONFDIR}"
98 return 1
99 fi
100 velist=$(grep -l '^ONBOOT=yes\|^ONBOOT=\"yes\"' [0-9]*.conf 2>/dev/null | sed -e 's/.conf//g' | sort -n)
101 cd - >/dev/null
102
103 /sbin/sysctl -q -w net.ipv4.route.src_check=0
104
105 for veid in ${velist}; do
106 ebegin "Starting VPS ${veid}"
107 if [ "${VZFASTBOOT}" = "yes" -a "${DISK_QUOTA}" = "yes" ]; then
108 ${VZQUOTA} stat ${veid} >/dev/null 2>&1
109 if [ $? -eq 6 ]; then
110 if ${VZQUOTA} show ${veid} 2>&1 | grep "vzquota : (warning) Quota is running" >/dev/null 2>&1; then
111 ${VZQUOTA} on ${veid} --nocheck >/dev/null 2>&1
112 need_restart="${need_restart} ${veid}"
113 fi
114 fi
115 fi
116 msg=$(${VZCTL} start ${veid} 2>&1)
117 eend $? "${msg}"
118 done
119
120 for veid in ${need_restart}; do
121 ebegin "Stopping VPS ${veid}"
122 msg=$(${VZCTL} stop ${veid})
123 eend $? "${msg}"
124
125 ebegin "Starting VPS ${veid}"
126 msg=$($VZCTL start ${veid} 2>&1)
127 eend $? "${msg}"
128 done
129
130 # we're ok even if some VPSs failed to start
131 return 0
132 }
133
134 stop_ve() {
135 local veid velist msg m mounts fail i iter pid pids quota
136
137 if [ -f ${VZVEINFO} ]; then
138 for ((i = 0; i <= 2; i++)); do
139 iter=0
140 pids=
141 velist=$(awk '{print $1;}' < ${VZVEINFO} | grep -v "^0$")
142
143 for veid in ${velist}; do
144 ebegin "Shutting down VPS $veid"
145 # Set fairsched parameters to maximum so
146 # VPS will stop fast
147 ${VZCTL} set ${veid} --cpuunits 2000 --cpulimit 0 >/dev/null 2>&1
148 ${VZCTL} --skiplock stop ${veid} >/dev/null 2>&1 &
149 pids="${pids} $!"
150 let iter++
151 sleep 1
152 if [ ${iter} -gt ${PARALLEL} ]; then
153 for pid in ${pids}; do
154 wait ${pid}
155 done
156 pids=
157 iter=0
158 fi
159 done
160
161 for pid in ${pids}; do
162 wait ${pid}
163 done
164 done
165 fi
166
167 iter=0
168 fail=1
169
170 while [ ${iter} -lt 5 -a ${fail} -ne 0 ]; do
171 fail=0
172 mounts=$(awk '{if ($3=="simfs") print $2}' /proc/mounts)
173
174 for m in ${mounts}; do
175 ebegin "Unmounting VPS area ${m}"
176 msg=$(umount ${m} 2>&1)
177 eend $? "${msg}"
178 if [ $? -ne 0 ]; then
179 let fail++
180 fuser -k -m ${m} > /dev/null 2>&1
181 fi
182 done
183
184 let iter++
185 done
186
187 # turn quota off
188 quota=$(awk -F: '/^[0-9]+:/{print $1}' /proc/vz/vzquota 2>/dev/null)
189
190 for m in ${quota}; do
191 ebegin "Turning quota off for VPS ${m}"
192 msg=$(vzquota off ${m} 2>&1)
193 eend $? "${msg}"
194 done
195 }
196
197 start() {
198 check_config || return
199
200 local msg mod rc
201
202 ebegin "Loading OpenVZ modules"
203 for mod in ${PRELOAD_MODULES}; do
204 /sbin/modprobe -r ${mod} >/dev/null 2>&1
205 /sbin/modprobe ${mod} >/dev/null 2>&1
206 done
207
208 for mod in ${MODULES}; do
209 /sbin/modprobe ${mod} >/dev/null 2>&1
210 rc=$?
211 if [ ${rc} -ne 0 ]; then
212 eend ${rc} "failed to load module ${mod}"
213 return ${rc}
214 fi
215 done
216 eend
217
218 start_net
219
220 msg=$(${VZCTL} set 0 --cpuunits ${VE0CPUUNITS} 2>&1)
221 [ $? -ne 0 ] && ewarn "vzctl set 0 --cpuunits ${VE0CPUUNITS} failed: ${msg}"
222
223 start_ve
224 }
225
226 stop() {
227 check_config || return
228
229 local mod
230
231 stop_ve
232 stop_net
233
234 for mod in ${MODULES}; do
235 /sbin/modprobe -r ${mod} > /dev/null 2>&1
236 done
237
238 for mod in ${PRELOAD_MODULES}; do
239 /sbin/modprobe -r ${mod} > /dev/null 2>&1
240 done
241
242 # Even if some modules failed to unload (say they were not loaded)
243 # we return 0 for the service to be marked as stopped.
244 return 0
245 }

  ViewVC Help
Powered by ViewVC 1.1.20