2 # Copyright (C) 2000-2009, Parallels, Inc. All rights reserved.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # OpenVZ startup script, used for redhat and debian related distributions.
22 # chkconfig: 2345 96 88
23 # description: OpenVZ startup script.
28 # Required-start: $network $remote_fs $syslog
29 # Required-stop: $network $remote_fs $syslog
30 # Should-Start: sshd vzeventd
31 # Should-Stop: sshd vzeventd
32 # Default-Start: 2 3 4 5
34 # Short-Description: OpenVZ startup script
35 # Description: OpenVZ startup script.
39 # This line is needed to cheat /etc/init.d/rc who expects action word
41 . /etc/rc.d/init.d/functions
42 . @SCRIPTDIR@/initd-functions
44 VZQUOTA=@SBINDIR@/vzquota
45 CONFIG_DIR=@PKGCONFDIR@/conf
46 LOCKFILE=/var/lock/subsys/vz_lock
47 SUBSYS_VZ=/var/lock/subsys/vz
48 VESTAT=/proc/vz/vestat
56 if [ "${MODULES_DISABLED}" != "yes" ]; then
57 PRELOAD_MODULES="af_packet"
58 MODULES="vzmon vzdquota vzdev"
59 CPT_MODULES="vzcpt vzrst"
60 MODULES_OTHER="vzcompat ${CPT_MODULES}"
61 VNET_MODULES="vznetdev vznet"
62 VETH_MODULES="vzethdev"
63 NET_MODULES="${VNET_MODULES} ${VETH_MODULES}"
64 if [ "${VZWDOG}" = "yes" ]; then
65 MODULES="${MODULES} vzwdog"
67 IPT_MODULES="ip_tables ${IPTABLES} xt_tcpudp"
68 if [ "${IPV6}" = "yes" ]; then
69 IPT_MODULES="${IPT_MODULES} ${IP6TABLES}"
77 # Number of the containers to stop in parallel.
78 # In case of empty value the number of CTs is calculated as 'num_cpu * 4'
84 if ! test -d /proc/vz ; then
86 print_warning "Running kernel is not OpenVZ kernel."
93 [ ! -z "$KERNEL_MAJOR" ] && return
96 local kernel=$(echo $ver | sed s/[-+].*//)
97 KERNEL_MAJOR=$(echo $kernel | awk -F . '{print $1}')
98 KERNEL_MINOR=$(echo $kernel | awk -F . '{print $2}')
99 KERNEL_PATCHLEVEL=$(echo $kernel | awk -F . '{print $3}')
102 check_kernel_config()
104 test -r /proc/config.gz || return 0
107 local opt_must="SIM_FS VE VE_CALLS VZ_GENCALLS"
109 # For kernels >= 2.6.9 VZ_DEV must be set.
110 test "${KERNEL_MINOR}" -ge 6 &&
111 test "${KERNEL_PATCHLEVEL}" -gt 9 &&
112 opt_must="${opt_must} VZ_DEV"
113 # local opt_rec="SCHED_VCPU FAIRSCHED VZ_QUOTA VZ_QUOTA_UGID VE_NETDEV VE_ETHDEV
114 # VE_IPTABLES VZ_CHECKPOINT VZ_WDOG"
116 conf="`zcat /proc/config.gz 2>/dev/null | grep -E -v '^#|^$'`"
118 for opt in $opt_must; do
119 if ! echo "$conf" 2>/dev/null | grep -q "$opt="; then
120 show "ERROR: Missing kernel config option: CONFIG_$opt"
124 if [ $err != 0 ]; then
126 print_warning "Please recompile your kernel."
133 [ -n "${PARALLEL}" ] && return
136 $1 == "processor" { num++; }
137 END { print num * 4; }' /proc/cpuinfo`
142 if [ -f /proc/vz/veinfo ]; then
143 VEINFO=/proc/vz/veinfo
144 elif [ -f /proc/veinfo ]; then
146 elif [ ! -f $VESTAT ]; then
154 get_veinfo || return 1
155 [ -f $SUBSYS_VZ ] || return 1
163 nls "OpenVZ is running..."
166 nls "OpenVZ is stopped."
175 # load all kernel modules needed for containers networking
176 for mod in ${NET_MODULES}; do
177 modprobe ${mod} 2>/dev/null
180 if ip addr list | grep -q "venet0:.*UP" 2>/dev/null; then
185 if [ -z "$VEINFO" ]; then
188 show "Bringing up interface $VZDEV"
191 ip link set $VZDEV up
193 ip addr add 0.0.0.0/0 dev $VZDEV
194 if [ "${IPV6}" = "yes" ]; then
195 ip -6 addr add fe80::1/128 dev $VZDEV
197 sysctl -q -w net.ipv4.conf.$VZDEV.send_redirects=0
198 if [ "$(sysctl -n -e net.ipv4.ip_forward)" != "1" ]; then
199 print_warning "Warning ! IP forwarding is not enabled !"
207 if ip addr list | grep -q "venet0:.*UP" 2>/dev/null; then
208 show "Bringing down interface $VZDEV"
209 ip link set $VZDEV down
212 for mod in ${NET_MODULES}; do
213 /sbin/modprobe -r ${mod} > /dev/null 2>&1
219 if test -z "${VE0CPUUNITS}"; then
220 echo "Warning: VE0CPUUNITS is not set in ${VZCONF}; using value of 1000"
223 msg=`${VZCTL} set 0 --cpuunits ${VE0CPUUNITS} 2>&1`
224 if [ $? -ne 0 ]; then
226 print_warning "vzctl set 0 --cpuunits ${VE0CPUUNITS} failed: $msg"
229 if ! test -f "${CONFIG_DIR}/0.conf"; then
232 if ! grep -q '^ONBOOT=yes\|^ONBOOT=\"yes\"' ${CONFIG_DIR}/0.conf;
236 show "Configure node UB resources: "
237 msg=`$VZCTL set 0 --reset_ub 2>&1`
249 velist=$(vzlist -aH -octid,onboot -s-bootorder |
250 awk '$2 == "yes" {print $1}')
251 sysctl -q -w net.ipv4.route.src_check=0
252 for veid in $velist; do
253 [ "${veid}" = "0" ] && continue
254 show "Starting CT ${veid}"
255 if [ "x${VZFASTBOOT}" = "xyes" -a "x${DISK_QUOTA}" = "xyes" ];
257 $VZQUOTA stat ${veid} >/dev/null 2>&1
258 if [ $? -eq 6 ]; then
259 if $VZQUOTA show ${veid} 2>&1 | grep "vzquota : (warning) Quota is running" >/dev/null 2>&1; then
260 $VZQUOTA on ${veid} --nocheck >/dev/null 2>&1
261 need_restart="${need_restart} ${veid}"
265 msg=`$VZCTL start ${veid} 2>&1`
268 for veid in ${need_restart}; do
269 msg_stopping "CT ${veid}: "
272 $VZCTL stop ${veid} 2>&1 >/dev/null 2>&1
274 msg_starting "CT ${veid}: "
277 msg=`$VZCTL start ${veid} 2>&1`
299 velist=`awk '$1 != "VEID" && $1 != "Version:" {print $1}' ${VESTAT}`
300 for veid in $velist; do
301 msg_stopping "CT $veid"
304 # Set fairsched parameters to maximum so
306 $VZCTL set $veid --cpuunits 2000 --cpulimit 0 >/dev/null 2>&1
307 $VZCTL --skiplock stop $veid >/dev/null 2>&1 &
310 if [ ${iter} -gt ${PARALLEL} ]; then
311 for pid in ${pids}; do
325 while test $iter -lt 5 -a $fail -ne 0; do
327 mounts=`awk '{if ($3=="simfs") print $2}' /proc/mounts`
329 show "Unmounting CT area "
332 if [ $? -eq 0 ]; then
338 fuser -k -m ${m} > /dev/null 2>&1
344 quota=`awk -F: '/^[0-9]+:/{print $1}' /proc/vz/vzquota 2>/dev/null`
345 for m in ${quota}; do
346 show "Turn quota off for CT "
348 msg=`vzquota off ${m} 2>&1`
355 local TEMPFILE="${1}.$$"
356 local LOCKFILE="${1}"
358 trap -- "rm -f ${LOCKFILE} ${TEMPFILE}" EXIT
360 echo $$ > ${TEMPFILE} 2> /dev/null || {
361 echo "Can't write to ${TEMPFILE}"
363 ln ${TEMPFILE} ${LOCKFILE} >/dev/null 2>&1 && {
367 kill -0 `cat $LOCKFILE` >/dev/null 2>&1 && {
370 ln ${TEMPFILE} ${LOCKFILE} >/dev/null 2>&1 && {
375 echo $$ > ${LOCKFILE}
389 if ! lockfile $LOCKFILE; then
390 show "OpenVZ is locked"
394 if [ -f ${SUBSYS_VZ} ]; then
395 nls "OpenVZ already running"
398 msg_starting "OpenVZ"
399 if [ "$?" = "0" ]; then
404 load_modules "${IPT_MODULES}"
405 for mod in $PRELOAD_MODULES; do
406 /sbin/modprobe -r $mod >/dev/null 2>&1
407 /sbin/modprobe $mod >/dev/null 2>&1
409 for mod in $MODULES; do
410 /sbin/modprobe $mod >/dev/null 2>&1
412 if [ $RETVAL -ne 0 ]; then
414 print_warning "failed to load module ${mod}"
418 load_modules "${MODULES_OTHER} ${VZFS_MODULES}"
419 show "loading OpenVZ modules"
422 if [ ! -e /dev/vzctl ]; then
423 # On most modern distros udev will create a device for you,
424 # while on the old distros /dev/vzctl comes with vzctl rpm.
425 # So the below mknod call is probably not needed at all.
426 /bin/mknod -m 600 /dev/vzctl c 126 0 > /dev/null 2>&1
428 if [ $RETVAL -ne 0 ]; then
430 print_warning "creating /dev/vzctl"
447 # Avoid stop action inside a CT, check we are in CT0
448 if ! egrep -q '^[[:space:]]*0:[[:space:]]' \
449 /proc/user_beancounters; then
450 print_failure "Looks like we are inside a container!"
455 if ! lockfile $LOCKFILE; then
456 show "OpenVZ is locked"
464 msg_stopping "OpenVZ"
465 for mod in ${MODULES_OTHER} ${MODULES} ${PRELOAD_MODULES} ${IPT_MODULES} ${VZFS_MODULES}; do
466 /sbin/modprobe -r ${mod} > /dev/null 2>&1
478 for mod in ${modules}; do
479 if /sbin/lsmod | grep -qw ${mod}; then
482 /sbin/modprobe ${mod} >/dev/null 2>&1
486 # See how we were called.
494 restart|force-reload)
503 echo "Usage: $0 {start|stop|status|restart|force-reload}"