slitaz-vz diff base-scripts/vz @ rev 6

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 08:27:32 2019 +0100 (2019-02-26)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/base-scripts/vz	Tue Feb 26 08:27:32 2019 +0100
     1.3 @@ -0,0 +1,604 @@
     1.4 +#!/bin/sh
     1.5 +#  Copyright (C) 2000-2008, Parallels, Inc. All rights reserved.
     1.6 +#
     1.7 +#  This program is free software; you can redistribute it and/or modify
     1.8 +#  it under the terms of the GNU General Public License as published by
     1.9 +#  the Free Software Foundation; either version 2 of the License, or
    1.10 +#  (at your option) any later version.
    1.11 +#
    1.12 +#  This program is distributed in the hope that it will be useful,
    1.13 +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 +#  GNU General Public License for more details.
    1.16 +#
    1.17 +#  You should have received a copy of the GNU General Public License
    1.18 +#  along with this program; if not, write to the Free Software
    1.19 +#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.20 +#
    1.21 +#
    1.22 +# OpenVZ startup script, used for redhat and debian related distributions.
    1.23 +
    1.24 +###
    1.25 +# description: OpenVZ startup script.
    1.26 +###
    1.27 +
    1.28 +VZCONF=/etc/vz/vz.conf
    1.29 +
    1.30 +[ -f ${VZCONF} ] || exit 0
    1.31 +. ${VZCONF}
    1.32 +[ "${VIRTUOZZO}" = "no" ] && exit 0
    1.33 +
    1.34 +VZCTL=/usr/sbin/vzctl
    1.35 +[ -x ${VZCTL} ] || exit 0
    1.36 +
    1.37 +VZQUOTA=/usr/sbin/vzquota
    1.38 +CONFIG_DIR=/etc/vz/conf
    1.39 +LOCKFILE=/var/lock/subsys/vz_lock
    1.40 +SUBSYS_VZ=/var/lock/subsys/vz
    1.41 +VESTAT=/proc/vz/vestat
    1.42 +VZDEV=venet0
    1.43 +PRELOAD_MODULES=
    1.44 +MODULES=
    1.45 +MODULES_OTHER=
    1.46 +NET_MODULES=
    1.47 +IPT_MODULES=
    1.48 +
    1.49 +if [ "${MODULES_DISABLED}" != "yes" ]; then
    1.50 +	PRELOAD_MODULES="af_packet"
    1.51 +	MODULES="vzmon vzdquota vzdev"
    1.52 +	CPT_MODULES="vzcpt vzrst"
    1.53 +	MODULES_OTHER="vzcompat ${CPT_MODULES}"
    1.54 +	VNET_MODULES="vznetdev vznet"
    1.55 +	VETH_MODULES="vzethdev"
    1.56 +	NET_MODULES="${VNET_MODULES} ${VETH_MODULES}"
    1.57 +	if [ "${VZWDOG}" = "yes" ]; then
    1.58 +		MODULES="${MODULES} vzwdog"
    1.59 +	fi
    1.60 +	IPT_MODULES="ip_tables ${IPTABLES} xt_tcpudp"
    1.61 +	if [ "${IPV6}" = "yes" ]; then
    1.62 +    		IPT_MODULES="${IPT_MODULES} ${IP6TABLES}"
    1.63 +	fi
    1.64 +	VZFS_MODULES="simfs"
    1.65 +fi
    1.66 +
    1.67 +
    1.68 +rc_done='..done'
    1.69 +rc_failed='..failed'
    1.70 +
    1.71 +# Source function library.
    1.72 +if [ -r /etc/init.d/functions ]; then
    1.73 +	source /etc/init.d/functions
    1.74 +	if [ -r /etc/redhat-release ] || [ -r /etc/centos-release ]; then
    1.75 +		DISTR=redhat
    1.76 +	fi
    1.77 +elif [ -r /etc/rc.status ]; then
    1.78 +	source /etc/rc.status
    1.79 +	if [ -r /etc/SuSE-release ]; then
    1.80 +		DISTR=suse
    1.81 +	fi
    1.82 +elif [ -r /etc/debian_version ]; then
    1.83 +	DISTR=debian
    1.84 +	LOCKFILE=/var/lock/vz_lock
    1.85 +	SUBSYS_VZ=/var/lock/vz
    1.86 +elif [ -r /etc/slitaz-release ]; then
    1.87 +	DISTR=slitaz
    1.88 +	LOCKFILE=/var/lock/vz_lock
    1.89 +	SUBSYS_VZ=/var/lock/vz
    1.90 +fi
    1.91 +
    1.92 +VEINFO=""
    1.93 +RETVAL=0
    1.94 +# Number of the containers to stop in parallel.
    1.95 +# In case of empty value the number of CTs is calculated as 'num_cpu * 4'
    1.96 +PARALLEL=
    1.97 +cd /
    1.98 +
    1.99 +# We used to install OpenVZ cron job when the vzctl package was
   1.100 +# installed, irrespective of whether OpenVZ was actually being
   1.101 +# run. Although the cron jobs didn't create any problems if someone
   1.102 +# wasn't running OpenVZ some users complained about the cron log file
   1.103 +# filling up, resource usage, and power consumption since systems
   1.104 +# wouldn't really idle. It really only makes sense to run the OpenVZ
   1.105 +# cron job if the vz service is turned on and not just merely
   1.106 +# having the package installed. This init.d script is an obvious place
   1.107 +# to install or remove the cron jobs based on the service
   1.108 +# being enabled or not.
   1.109 +SRC_CRONSCRIPT_DIR=/etc/vz/cron
   1.110 +DST_CRONSCRIPT_DIR=/etc/cron.d
   1.111 +
   1.112 +check_old_cron_files()
   1.113 +{
   1.114 +	# avoid double OpenVZ cron settings
   1.115 +	local f
   1.116 +	for f in vpsreboot vpsnetclean; do
   1.117 +		[ -f $DST_CRONSCRIPT_DIR/$f ] && rm -f $DST_CRONSCRIPT_DIR/$f
   1.118 +	done
   1.119 +}
   1.120 +
   1.121 +setup_cron()
   1.122 +{
   1.123 +	check_old_cron_files
   1.124 +	[ -z "$SRC_CRONSCRIPT_DIR" ] && return
   1.125 +	[ -d "$SRC_CRONSCRIPT_DIR" ] || return
   1.126 +	cat $SRC_CRONSCRIPT_DIR/vz* > $DST_CRONSCRIPT_DIR/vz &&
   1.127 +		chmod 644 $DST_CRONSCRIPT_DIR/vz
   1.128 +}
   1.129 +
   1.130 +remove_cron()
   1.131 +{
   1.132 +	check_old_cron_files
   1.133 +	[ -z "$SRC_CRONSCRIPT_DIR" ] && return
   1.134 +	[ -d "$SRC_CRONSCRIPT_DIR" ] || return
   1.135 +	cat > $DST_CRONSCRIPT_DIR/vz <<EOF
   1.136 +# DO NOT EDIT THIS FILE!
   1.137 +#
   1.138 +# Contents of this file managed by /etc/init.d/vz script
   1.139 +# Master copy is in $SRC_CRONSCRIPT_DIR/vz* file(s).
   1.140 +# Consult $SRC_CRONSCRIPT_DIR/vz* for documentation.
   1.141 +EOF
   1.142 +}
   1.143 +
   1.144 +# Actualize OpenVZ cron entry:
   1.145 +# if OpenVZ is running, add it, otherwise remove.
   1.146 +update_cron()
   1.147 +{
   1.148 +	if is_running; then
   1.149 +		__echo "Adding OpenVZ cron entries"
   1.150 +		setup_cron
   1.151 +	else
   1.152 +		__echo "Removing OpenVZ cron entries"
   1.153 +		remove_cron
   1.154 +	fi
   1.155 +	print_result
   1.156 +}
   1.157 +
   1.158 +check_kernel()
   1.159 +{
   1.160 +	if ! test -d /proc/vz ; then
   1.161 +		print_failure "Running kernel is not OpenVZ kernel."
   1.162 +		exit 1
   1.163 +	fi
   1.164 +}
   1.165 +
   1.166 +get_kernel_version()
   1.167 +{
   1.168 +	[ ! -z "$KERNEL_MAJOR" ] && return
   1.169 +
   1.170 +	local ver=$(uname -r)
   1.171 +	local kernel=$(echo $ver | sed s/[-+].*//)
   1.172 +	KERNEL_MAJOR=$(echo $kernel | awk -F . '{print $1}')
   1.173 +	KERNEL_MINOR=$(echo $kernel | awk -F . '{print $2}')
   1.174 +	KERNEL_PATCHLEVEL=$(echo $kernel | awk -F . '{print $3}')
   1.175 +}
   1.176 +
   1.177 +check_kernel_config()
   1.178 +{
   1.179 +	test -r /proc/config.gz || return 0
   1.180 +
   1.181 +	local conf opt err=0
   1.182 +	local opt_must="SIM_FS VE VE_CALLS VZ_GENCALLS"
   1.183 +	get_kernel_version
   1.184 +	# For kernels >= 2.6.9 VZ_DEV must be set.
   1.185 +	test "${KERNEL_MINOR}" -ge 6 &&
   1.186 +		test "${KERNEL_PATCHLEVEL}" -gt 9 &&
   1.187 +			opt_must="${opt_must} VZ_DEV"
   1.188 +#	local opt_rec="SCHED_VCPU FAIRSCHED VZ_QUOTA VZ_QUOTA_UGID VE_NETDEV VE_ETHDEV
   1.189 +#			VE_IPTABLES VZ_CHECKPOINT VZ_WDOG"
   1.190 +
   1.191 +	conf="`zcat /proc/config.gz 2>/dev/null | grep -E -v '^#|^$'`"
   1.192 +
   1.193 +	for opt in $opt_must; do
   1.194 +		if ! echo "$conf" 2>/dev/null | grep -q "$opt="; then
   1.195 +			echo "ERROR: Missing kernel config option: CONFIG_$opt"
   1.196 +			err=1
   1.197 +		fi
   1.198 +	done
   1.199 +	if [ $err != 0 ]; then
   1.200 +		print_failure "Please recompile your kernel."
   1.201 +		exit 1
   1.202 +	fi
   1.203 +}
   1.204 +
   1.205 +get_parallel()
   1.206 +{
   1.207 +	[ -n "${PARALLEL}" ] && return
   1.208 +	PARALLEL=`awk '
   1.209 +BEGIN { num=0; }
   1.210 +$1 == "processor" { num++; }
   1.211 +END { print num * 4; }' /proc/cpuinfo`
   1.212 +}
   1.213 +
   1.214 +get_veinfo()
   1.215 +{
   1.216 +	if [ -f /proc/vz/veinfo ]; then
   1.217 +		VEINFO=/proc/vz/veinfo
   1.218 +	elif [ -f /proc/veinfo ]; then
   1.219 +		VEINFO=/proc/veinfo
   1.220 +	elif [ ! -f $VESTAT ]; then
   1.221 +		return 1
   1.222 +	fi
   1.223 +	return 0
   1.224 +}
   1.225 +
   1.226 +print_success()
   1.227 +{
   1.228 +	if [ "$DISTR" = "redhat" ]; then
   1.229 +		echo_success
   1.230 +	else
   1.231 +		echo -n "$rc_done"
   1.232 +	fi
   1.233 +	echo
   1.234 +}
   1.235 +
   1.236 +print_failure()
   1.237 +{
   1.238 +	echo -n "$1"
   1.239 +	if [ "$DISTR" = "redhat" ]; then
   1.240 +		failure $"$1"
   1.241 +	else
   1.242 +		echo -n "$rc_failed"
   1.243 +	fi
   1.244 +	echo
   1.245 +}
   1.246 +
   1.247 +# Calls either print_success or print_failure, depending on $?
   1.248 +# Optional argument $1 -- an error string passed to print_failure.
   1.249 +print_result()
   1.250 +{
   1.251 +	if [ $? -eq 0 ] ; then
   1.252 +		print_success
   1.253 +	else
   1.254 +		print_failure "$1"
   1.255 +	fi
   1.256 +}
   1.257 +
   1.258 +__echo()
   1.259 +{
   1.260 +	if [ "$DISTR" = "redhat" ]; then
   1.261 +		echo -n $"$1"
   1.262 +	else
   1.263 +		echo -n "$1"
   1.264 +	fi
   1.265 +}
   1.266 +
   1.267 +is_running()
   1.268 +{
   1.269 +	get_veinfo || return 1
   1.270 +	[ -f $SUBSYS_VZ ] || return 1
   1.271 +}
   1.272 +
   1.273 +status()
   1.274 +{
   1.275 +	check_kernel
   1.276 +
   1.277 +	if is_running; then
   1.278 +		echo "OpenVZ is running..."
   1.279 +		return 0
   1.280 +	else
   1.281 +		echo "OpenVZ is stopped."
   1.282 +		return 3
   1.283 +	fi
   1.284 +}
   1.285 +
   1.286 +start_net()
   1.287 +{
   1.288 +	local mod
   1.289 +
   1.290 +	# load all kernel modules needed for containers networking
   1.291 +	for mod in ${NET_MODULES}; do
   1.292 +		modprobe ${mod} 2>/dev/null
   1.293 +	done
   1.294 +
   1.295 +	if ip addr list | grep -q "venet0:.*UP" 2>/dev/null; then
   1.296 +		return 0
   1.297 +	fi
   1.298 +
   1.299 +	get_veinfo
   1.300 +	if [ -z "$VEINFO" ]; then
   1.301 +		return 0
   1.302 +	fi
   1.303 +	__echo "Bringing up interface $VZDEV: "
   1.304 +	ip link set $VZDEV up
   1.305 +	print_result
   1.306 +	ip addr add 0.0.0.0/0 dev $VZDEV
   1.307 +	__echo "Configuring interface $VZDEV: "
   1.308 +	sysctl -w net.ipv4.conf.$VZDEV.send_redirects=0
   1.309 +	print_result
   1.310 +	if [ "${IPV6}" = "yes" ]; then
   1.311 +		__echo "Configuring ipv6 $VZDEV: "
   1.312 +		# Fix me: ip addres should be generated
   1.313 +		ip -6 addr add fe80::1/128 dev $VZDEV
   1.314 +		print_result
   1.315 +	fi
   1.316 +}
   1.317 +
   1.318 +stop_net()
   1.319 +{
   1.320 +	local mod
   1.321 +
   1.322 +	if ip addr list | grep -q "venet0:.*UP" 2>/dev/null; then
   1.323 +		__echo "Bringing down interface $VZDEV: "
   1.324 +		ip link set $VZDEV down
   1.325 +		print_result
   1.326 +	fi
   1.327 +	for mod in ${NET_MODULES}; do
   1.328 +		/sbin/modprobe -r ${mod} > /dev/null 2>&1
   1.329 +	done
   1.330 +}
   1.331 +
   1.332 +setup_ve0()
   1.333 +{
   1.334 +	if test -z "${VE0CPUUNITS}"; then
   1.335 +		echo "Warning: VE0CPUUNITS is not set in ${VZCONF}; using value of 1000"
   1.336 +		VE0CPUUNITS=1000
   1.337 +	fi
   1.338 +	msg=`${VZCTL} set 0 --cpuunits ${VE0CPUUNITS} 2>&1`
   1.339 +	if [ $? -ne 0 ]; then
   1.340 +		print_failure "vzctl set 0 --cpuunits ${VE0CPUUNITS} failed: $msg"
   1.341 +	fi
   1.342 +
   1.343 +	if ! test -f "${CONFIG_DIR}/0.conf"; then
   1.344 +		return
   1.345 +	fi
   1.346 +	if ! grep -q '^ONBOOT=yes\|^ONBOOT=\"yes\"' ${CONFIG_DIR}/0.conf;
   1.347 +	then
   1.348 +		return
   1.349 +	fi
   1.350 +	__echo "Configure node UB resources: "
   1.351 +	msg=`$VZCTL set 0 --reset_ub 2>&1`
   1.352 +	print_result "$msg"
   1.353 +}
   1.354 +
   1.355 +start_ves()
   1.356 +{
   1.357 +	local veid
   1.358 +	local velist
   1.359 +	local msg
   1.360 +	local need_restart
   1.361 +
   1.362 +	need_restart=""
   1.363 +	cd ${CONFIG_DIR} || return
   1.364 +	velist=`grep -l '^ONBOOT=yes\|^ONBOOT=\"yes\"' [0-9]*.conf 2>/dev/null |
   1.365 +		sed -e 's/.conf//g' | sort -n`
   1.366 +	cd - >/dev/null
   1.367 +	sysctl -w net.ipv4.route.src_check=0
   1.368 +	for veid in $velist; do
   1.369 +		[ "${veid}" = "0" ] && continue
   1.370 +		__echo "Starting CT ${veid}: "
   1.371 +		if [ "x${VZFASTBOOT}" = "xyes" -a "x${DISK_QUOTA}" = "xyes" ];
   1.372 +		then
   1.373 +			$VZQUOTA stat ${veid} >/dev/null 2>&1
   1.374 +			if [ $? -eq 6 ]; then
   1.375 +				if $VZQUOTA show ${veid} 2>&1 | grep "vzquota : (warning) Quota is running" >/dev/null 2>&1; then
   1.376 +					$VZQUOTA on ${veid} --nocheck >/dev/null 2>&1
   1.377 +					need_restart="${need_restart} ${veid}"
   1.378 +				fi
   1.379 +			fi
   1.380 +		fi
   1.381 +		msg=`$VZCTL start ${veid} 2>&1`
   1.382 +		print_result "$msg"
   1.383 +	done
   1.384 +	for veid in ${need_restart}; do
   1.385 +		__echo "Stopping CT ${veid}: "
   1.386 +		$VZCTL stop ${veid} 2>&1 >/dev/null 2>&1
   1.387 +		print_result "$msg"
   1.388 +		__echo "Starting CT ${veid}: "
   1.389 +		msg=`$VZCTL start ${veid} 2>&1`
   1.390 +		print_result "$msg"
   1.391 +	done
   1.392 +}
   1.393 +
   1.394 +stop_ves()
   1.395 +{
   1.396 +	local veid
   1.397 +	local velist
   1.398 +	local msg
   1.399 +	local m
   1.400 +	local mounts
   1.401 +	local fail
   1.402 +	local iter
   1.403 +	local quota
   1.404 +	local pids
   1.405 +
   1.406 +	if get_veinfo; then
   1.407 +		get_parallel
   1.408 +		for i in 0 1 2; do
   1.409 +			iter=0;
   1.410 +			pids=
   1.411 +			velist=`awk '$1 != "VEID" && $1 != "Version:" {print $1}' ${VESTAT}`
   1.412 +			for veid in $velist; do
   1.413 +				echo "Shutting down CT $veid"
   1.414 +				# Set fairsched parameters to maximum so
   1.415 +				# CT will stop fast
   1.416 +				$VZCTL set $veid --cpuunits 2000 --cpulimit 0 >/dev/null 2>&1
   1.417 +				$VZCTL --skiplock stop $veid >/dev/null 2>&1 &
   1.418 +				pids="$pids $!"
   1.419 +				iter=$(($iter+1))
   1.420 +				if [ ${iter} -gt ${PARALLEL} ]; then
   1.421 +					for pid in ${pids}; do
   1.422 +						wait ${pid}
   1.423 +					done
   1.424 +					pids=
   1.425 +					iter=0
   1.426 +				fi
   1.427 +			done
   1.428 +			for pid in $pids; do
   1.429 +				wait $pid
   1.430 +			done
   1.431 +		done
   1.432 +	fi
   1.433 +	iter=0
   1.434 +	fail=1
   1.435 +	while test $iter -lt 5 -a $fail -ne 0; do
   1.436 +		fail=0
   1.437 +		mounts=`awk '{if ($3=="simfs") print $2}' /proc/mounts`
   1.438 +		for m in $mounts; do
   1.439 +			__echo "Unmounting CT area "
   1.440 +			echo -n $m
   1.441 +			msg=`umount $m 2>&1`
   1.442 +			if [ $? -eq 0 ]; then
   1.443 +				print_success
   1.444 +			else
   1.445 +				print_failure "$msg"
   1.446 +				fail=$((fail+1))
   1.447 +				fuser -k -m ${m} > /dev/null 2>&1
   1.448 +			fi
   1.449 +		done
   1.450 +		iter=$(($iter+1))
   1.451 +	done
   1.452 +	# turn quota off
   1.453 +	quota=`awk -F: '/^[0-9]+:/{print $1}' /proc/vz/vzquota 2>/dev/null`
   1.454 +	for m in ${quota}; do
   1.455 +		__echo "Turn quota off for CT "
   1.456 +		echo -n $m
   1.457 +		msg=`vzquota off ${m} 2>&1`
   1.458 +		print_result "$msg"
   1.459 +	done
   1.460 +}
   1.461 +
   1.462 +lockfile()
   1.463 +{
   1.464 +	local TEMPFILE="${1}.$$"
   1.465 +	local LOCKFILE="${1}"
   1.466 +
   1.467 +	trap -- "rm -f ${LOCKFILE} ${TEMPFILE}" EXIT
   1.468 +
   1.469 +	echo $$ > ${TEMPFILE} 2> /dev/null || {
   1.470 +		echo "Can't write to ${TEMPFILE}"
   1.471 +	}
   1.472 +	ln ${TEMPFILE} ${LOCKFILE} >/dev/null 2>&1 && {
   1.473 +		rm -f ${TEMPFILE};
   1.474 +		return 0;
   1.475 +	}
   1.476 +	kill -0 `cat $LOCKFILE` >/dev/null 2>&1 && {
   1.477 +		return 1;
   1.478 +	}
   1.479 +	ln ${TEMPFILE} ${LOCKFILE} >/dev/null 2>&1 && {
   1.480 +		rm -f ${TEMPFILE};
   1.481 +		return 0;
   1.482 +	}
   1.483 +	rm -f ${LOCKFILE}
   1.484 +	echo $$ > ${LOCKFILE}
   1.485 +	return 0
   1.486 +}
   1.487 +
   1.488 +start()
   1.489 +{
   1.490 +	local veid
   1.491 +	local velist
   1.492 +	local msg
   1.493 +	local mod
   1.494 +
   1.495 +	check_kernel
   1.496 +	check_kernel_config
   1.497 +
   1.498 +	if ! lockfile $LOCKFILE; then
   1.499 +		__echo "OpenVZ is locked"
   1.500 +		print_failure
   1.501 +		return 1
   1.502 +	fi
   1.503 +	if [ -f ${SUBSYS_VZ} ]; then
   1.504 +		__echo "OpenVZ already running"
   1.505 +		print_failure
   1.506 +		return 1
   1.507 +	fi
   1.508 +	__echo "Starting OpenVZ: "
   1.509 +	load_modules "${IPT_MODULES}"
   1.510 +	for mod in $PRELOAD_MODULES; do
   1.511 +		/sbin/modprobe -r $mod >/dev/null 2>&1
   1.512 +		/sbin/modprobe $mod >/dev/null 2>&1
   1.513 +	done
   1.514 +	for mod in $MODULES; do
   1.515 +		/sbin/modprobe $mod >/dev/null 2>&1
   1.516 +		RETVAL=$?
   1.517 +		if [ $RETVAL -ne 0 ]; then
   1.518 +			print_failure "failed to load module ${mod}"
   1.519 +			return $RETVAL
   1.520 +		fi
   1.521 +	done
   1.522 +	load_modules "${MODULES_OTHER} ${VZFS_MODULES}"
   1.523 +	print_success "loading OpenVZ modules"
   1.524 +
   1.525 +	if [ ! -e /dev/vzctl ]; then
   1.526 +		# On most modern distros udev will create a device for you,
   1.527 +		# while on the old distros /dev/vzctl comes with vzctl rpm.
   1.528 +		# So the below mknod call is probably not needed at all.
   1.529 +		/bin/mknod -m 600 /dev/vzctl c 126 0 > /dev/null 2>&1
   1.530 +		RETVAL=$?
   1.531 +		if [ $RETVAL -ne 0 ]; then
   1.532 +			print_failure "creating /dev/vzctl"
   1.533 +			return $RETVAL
   1.534 +		fi
   1.535 +	fi
   1.536 +
   1.537 +	start_net
   1.538 +	setup_ve0
   1.539 +	setup_cron
   1.540 +	start_ves
   1.541 +
   1.542 +	rm -f $LOCKFILE
   1.543 +	touch $SUBSYS_VZ
   1.544 +}
   1.545 +
   1.546 +stop()
   1.547 +{
   1.548 +	local mod
   1.549 +
   1.550 +	if ! lockfile $LOCKFILE; then
   1.551 +		__echo "OpenVZ is locked"
   1.552 +		print_failure
   1.553 +		RETVAL=1
   1.554 +		return 1
   1.555 +	fi
   1.556 +
   1.557 +	stop_ves
   1.558 +	remove_cron
   1.559 +	stop_net
   1.560 +	__echo "Stopping OpenVZ: "
   1.561 +	for mod in ${MODULES_OTHER} ${MODULES} ${PRELOAD_MODULES} ${IPT_MODULES} ${VZFS_MODULES}; do
   1.562 +		/sbin/modprobe -r ${mod} > /dev/null 2>&1
   1.563 +	done
   1.564 +	rm -f $LOCKFILE
   1.565 +	rm -f $SUBSYS_VZ
   1.566 +	print_success
   1.567 +}
   1.568 +
   1.569 +load_modules()
   1.570 +{
   1.571 +	local modules=$1
   1.572 +	local mod
   1.573 +
   1.574 +	for mod in ${modules}; do
   1.575 +		if /sbin/lsmod | grep -qw ${mod}; then
   1.576 +			continue
   1.577 +		fi
   1.578 +		/sbin/modprobe ${mod} >/dev/null 2>&1
   1.579 +	done
   1.580 +}
   1.581 +
   1.582 +# See how we were called.
   1.583 +case "$1" in
   1.584 +  start)
   1.585 +	start
   1.586 +	;;
   1.587 +  stop)
   1.588 +	stop
   1.589 +	;;
   1.590 +  restart|force-reload)
   1.591 +	stop
   1.592 +	start
   1.593 +	;;
   1.594 +  status)
   1.595 +	status
   1.596 +	RETVAL=$?
   1.597 +	;;
   1.598 +  update-cron)
   1.599 +	update_cron
   1.600 +	RETVAL=0
   1.601 +	;;
   1.602 +  *)
   1.603 +	echo "Usage: $0 {start|stop|status|restart|force-reload|update-cron}"
   1.604 +	exit 1
   1.605 +esac
   1.606 +
   1.607 +exit $RETVAL