summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenedikt Boehm <hollow@gentoo.org>2005-11-23 21:55:54 +0000
committerBenedikt Boehm <hollow@gentoo.org>2005-11-23 21:55:54 +0000
commit7f26e0b8338f152b6b13b08da8a7117ea08e206b (patch)
tree13ee433ca8b530173c3311564eb711cabe3204aa /vzctl/init.d
parentadd split patches (diff)
downloadmisc-7f26e0b8338f152b6b13b08da8a7117ea08e206b.tar.gz
misc-7f26e0b8338f152b6b13b08da8a7117ea08e206b.tar.bz2
misc-7f26e0b8338f152b6b13b08da8a7117ea08e206b.zip
add vzctl stuff
svn path=/; revision=96
Diffstat (limited to 'vzctl/init.d')
-rw-r--r--vzctl/init.d/vz.initd245
1 files changed, 245 insertions, 0 deletions
diff --git a/vzctl/init.d/vz.initd b/vzctl/init.d/vz.initd
new file mode 100644
index 0000000..665be64
--- /dev/null
+++ b/vzctl/init.d/vz.initd
@@ -0,0 +1,245 @@
+#!/sbin/runscript
+# Copyright 1999-2005 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/sys-cluster/vzctl/files/vz.initd,v 1.1 2005/09/26 15:32:35 hollow Exp $
+
+depend() {
+ need net
+ before iptables
+}
+
+check_config() {
+ # if we don't want openvz running, say so
+ [ "${VIRTUOZZO}" = "yes" ] || return 1
+
+ # set default values
+ : ${VZCTL:=/usr/sbin/vzctl}
+ : ${VZQUOTA:=/usr/sbin/vzquota}
+ : ${VZVEINFO:=/proc/vz/veinfo}
+ : ${VPSCONFDIR:=/etc/vz}
+ : ${PRELOAD_MODULES:="af_packet"}
+ : ${MODULES:="vzmon vzdquota vzdev"}
+ : ${NET_MODULES="vznetdev vznet"}
+ : ${VZDEV:=venet0}
+ : ${PARALLEL:=4}
+
+ # check if you should load vzwdog module
+ [ "${VZWDOG}" = "yes" ] && MODULES="${MODULES} vzwdog"
+
+ # we need a working vzctl
+ if [ ! -x "${VZCTL}" ]; then
+ eerror "vzctl missing (${VZCTL})"
+ return 1
+ fi
+
+ # prevent dumb users from failure
+ if [ ! -e /dev/vzctl ]; then
+ eerror "Missing device node /dev/vzctl"
+ einfo
+ einfo "Please create the vzctl device node using the following command:"
+ einfo " /bin/mknod /dev/vzctl c 126 0"
+ einfo
+ return 1
+ fi
+
+ if [ -z "${VE0CPUUNITS}" ]; then
+ ewarn "VE0CPUUNITS is not set in /etc/conf.d/vz; using default value of 1000"
+ VE0CPUUNITS=1000
+ fi
+ return 0
+}
+
+start_net() {
+ local mod
+
+ # we don't operate on a running interface
+ if /sbin/ip addr ls | grep -q "venet0:.*UP" 2>/dev/null; then
+ return 0
+ fi
+
+ # load necessary modules
+ for mod in ${NET_MODULES}; do
+ /sbin/modprobe ${mod} 2>/dev/null
+ done
+
+ # configure the device
+ ebegin "Bringing up interface ${VZDEV}"
+ /sbin/ip link set ${VZDEV} up
+ eend $?
+
+ /sbin/ip addr add 0.0.0.0/0 dev ${VZDEV}
+
+ ebegin "Configuring interface ${VZDEV}"
+ /sbin/sysctl -q -w net.ipv4.conf.${VZDEV}.send_redirects=0
+ eend $?
+}
+
+stop_net() {
+ local mod
+
+ if /sbin/ip a l | grep -q "venet0:.*UP" 2>/dev/null; then
+ ebegin "Bringing down interface ${VZDEV}"
+ /sbin/ip link set ${VZDEV} down 2>/dev/null
+ eend $?
+ fi
+
+ # remove all modules we probably loaded on start_net
+ for mod in ${NET_MODULES}; do
+ /sbin/modprobe -r ${mod} > /dev/null 2>&1
+ done
+}
+
+start_ve() {
+ local veid velist msg need_restart=""
+
+ # get all VPSs we should start on boot
+ if ! cd ${VPSCONFDIR}; then
+ eerror $? "Unable to cd to ${VPSCONFDIR}"
+ return 1
+ fi
+ velist=$(grep -l '^ONBOOT=yes\|^ONBOOT=\"yes\"' [0-9]*.conf 2>/dev/null | sed -e 's/.conf//g' | sort -n)
+ cd - >/dev/null
+
+ /sbin/sysctl -q -w net.ipv4.route.src_check=0
+
+ for veid in ${velist}; do
+ ebegin "Starting VPS ${veid}"
+ if [ "${VZFASTBOOT}" = "yes" -a "${DISK_QUOTA}" = "yes" ]; then
+ ${VZQUOTA} stat ${veid} >/dev/null 2>&1
+ if [ $? -eq 6 ]; then
+ if ${VZQUOTA} show ${veid} 2>&1 | grep "vzquota : (warning) Quota is running" >/dev/null 2>&1; then
+ ${VZQUOTA} on ${veid} --nocheck >/dev/null 2>&1
+ need_restart="${need_restart} ${veid}"
+ fi
+ fi
+ fi
+ msg=$(${VZCTL} start ${veid} 2>&1)
+ eend $? "${msg}"
+ done
+
+ for veid in ${need_restart}; do
+ ebegin "Stopping VPS ${veid}"
+ msg=$(${VZCTL} stop ${veid})
+ eend $? "${msg}"
+
+ ebegin "Starting VPS ${veid}"
+ msg=$($VZCTL start ${veid} 2>&1)
+ eend $? "${msg}"
+ done
+
+ # we're ok even if some VPSs failed to start
+ return 0
+}
+
+stop_ve() {
+ local veid velist msg m mounts fail i iter pid pids quota
+
+ if [ -f ${VZVEINFO} ]; then
+ for ((i = 0; i <= 2; i++)); do
+ iter=0
+ pids=
+ velist=$(awk '{print $1;}' < ${VZVEINFO} | grep -v "^0$")
+
+ for veid in ${velist}; do
+ ebegin "Shutting down VPS $veid"
+ # Set fairsched parameters to maximum so
+ # VPS will stop fast
+ ${VZCTL} set ${veid} --cpuunits 2000 --cpulimit 0 >/dev/null 2>&1
+ ${VZCTL} --skiplock stop ${veid} >/dev/null 2>&1 &
+ pids="${pids} $!"
+ let iter++
+ sleep 1
+ if [ ${iter} -gt ${PARALLEL} ]; then
+ for pid in ${pids}; do
+ wait ${pid}
+ done
+ pids=
+ iter=0
+ fi
+ done
+
+ for pid in ${pids}; do
+ wait ${pid}
+ done
+ done
+ fi
+
+ iter=0
+ fail=1
+
+ while [ ${iter} -lt 5 -a ${fail} -ne 0 ]; do
+ fail=0
+ mounts=$(awk '{if ($3=="simfs") print $2}' /proc/mounts)
+
+ for m in ${mounts}; do
+ ebegin "Unmounting VPS area ${m}"
+ msg=$(umount ${m} 2>&1)
+ eend $? "${msg}"
+ if [ $? -ne 0 ]; then
+ let fail++
+ fuser -k -m ${m} > /dev/null 2>&1
+ fi
+ done
+
+ let iter++
+ done
+
+ # turn quota off
+ quota=$(awk -F: '/^[0-9]+:/{print $1}' /proc/vz/vzquota 2>/dev/null)
+
+ for m in ${quota}; do
+ ebegin "Turning quota off for VPS ${m}"
+ msg=$(vzquota off ${m} 2>&1)
+ eend $? "${msg}"
+ done
+}
+
+start() {
+ check_config || return
+
+ local msg mod rc
+
+ ebegin "Loading OpenVZ modules"
+ for mod in ${PRELOAD_MODULES}; do
+ /sbin/modprobe -r ${mod} >/dev/null 2>&1
+ /sbin/modprobe ${mod} >/dev/null 2>&1
+ done
+
+ for mod in ${MODULES}; do
+ /sbin/modprobe ${mod} >/dev/null 2>&1
+ rc=$?
+ if [ ${rc} -ne 0 ]; then
+ eend ${rc} "failed to load module ${mod}"
+ return ${rc}
+ fi
+ done
+ eend
+
+ start_net
+
+ msg=$(${VZCTL} set 0 --cpuunits ${VE0CPUUNITS} 2>&1)
+ [ $? -ne 0 ] && ewarn "vzctl set 0 --cpuunits ${VE0CPUUNITS} failed: ${msg}"
+
+ start_ve
+}
+
+stop() {
+ check_config || return
+
+ local mod
+
+ stop_ve
+ stop_net
+
+ for mod in ${MODULES}; do
+ /sbin/modprobe -r ${mod} > /dev/null 2>&1
+ done
+
+ for mod in ${PRELOAD_MODULES}; do
+ /sbin/modprobe -r ${mod} > /dev/null 2>&1
+ done
+
+ # Even if some modules failed to unload (say they were not loaded)
+ # we return 0 for the service to be marked as stopped.
+ return 0
+}