From 6860ee7b75b17e1ae7d8e3b8e9aadecfca4a08ca Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Thu, 28 Dec 2006 00:07:05 +0000 Subject: [PATCH] Move initscript functions to vserver-init.functions. Make vprocunhide use said functions. Add an initscript to set the helper and kill guest processes. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2434 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- contrib/manifest.dat.pathsubst | 2 + scripts/Makefile-files | 3 +- scripts/util-vserver-vars.pathsubst | 1 + scripts/vserver-init.functions | 50 +++++++++++++++++++++ scripts/vserver-wrapper | 35 +-------------- sysv/Makefile-files | 3 +- sysv/util-vserver | 88 +++++++++++++++++++++++++++++++++++++ sysv/vprocunhide | 25 +++-------- 8 files changed, 152 insertions(+), 55 deletions(-) create mode 100755 scripts/vserver-init.functions create mode 100755 sysv/util-vserver diff --git a/contrib/manifest.dat.pathsubst b/contrib/manifest.dat.pathsubst index ac0dd6a..2d49438 100644 --- a/contrib/manifest.dat.pathsubst +++ b/contrib/manifest.dat.pathsubst @@ -23,6 +23,7 @@ base @PKGLIBDIR@/vserver.start base @PKGLIBDIR@/vserver.stop base @PKGLIBDIR@/vserver.suexec base @PKGLIBDIR@/vserver.delete +sysv @PKGLIBDIR@/vserver-init.functions core @PKGLIBDIR@/util-vserver-vars build @PKGLIBDIR@/rpm-fake.so legacy @LEGACYDIR@/save_s_context @@ -139,6 +140,7 @@ legacy @CONFIG@ @INITRDDIR@/v_sshd legacy @CONFIG@ @INITRDDIR@/v_xinetd sysv @CONFIG@ @INITRDDIR@/vprocunhide sysv @CONFIG@ @INITRDDIR@/vservers-default +sysv @CONFIG@ @INITRDDIR@/util-vserver legacy @CONFIG@ @INITRDDIR@/rebootmgr legacy @CONFIG@ @INITRDDIR@/vservers-legacy legacy @CONFIG_NOREPLACE@ @SYSCONFDIR@/vservers.conf diff --git a/scripts/Makefile-files b/scripts/Makefile-files index fda81ee..7eeb981 100644 --- a/scripts/Makefile-files +++ b/scripts/Makefile-files @@ -57,7 +57,8 @@ scripts_pkglib_src_DTA = scripts/functions \ scripts/vserver.start \ scripts/vserver.stop \ scripts/vserver.suexec \ - scripts/vserver.delete + scripts/vserver.delete \ + scripts/vserver-init.functions scripts_pkglib_gen_DTA = scripts/util-vserver-vars diff --git a/scripts/util-vserver-vars.pathsubst b/scripts/util-vserver-vars.pathsubst index 28c4054..dbefd9b 100644 --- a/scripts/util-vserver-vars.pathsubst +++ b/scripts/util-vserver-vars.pathsubst @@ -45,6 +45,7 @@ _INITSYNC_MINIT_START=: _KEEP_CTX_ALIVE="$__PKGLIBDIR/keep-ctx-alive" _LIB_FUNCTIONS="$__PKGLIBDIR/functions" _LIB_MAGIC="$__PKGLIBDIR/magic" +_LIB_VSERVER_INIT_FUNCTIONS="$__PKGLIBDIR/vserver-init.functions" _LIB_VSERVER_SETUP_FUNCTIONS="$__PKGLIBDIR/vserver-setup.functions" _LIB_VSERVER_BUILD_FUNCTIONS="$__PKGLIBDIR/vserver-build.functions" _LIB_VSERVER_BUILD_FUNCTIONS_APT="$__PKGLIBDIR/vserver-build.functions.apt" diff --git a/scripts/vserver-init.functions b/scripts/vserver-init.functions new file mode 100755 index 0000000..1f1255a --- /dev/null +++ b/scripts/vserver-init.functions @@ -0,0 +1,50 @@ +#! /bin/bash + +# Copyright (C) 2004 Enrico Scholz +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +if test -e /etc/init.d/functions; then + . /etc/init.d/functions + _beginResult() { echo -n "$@..."; } + _postResult() { echo; } + lockfile=/var/lock/subsys/$LOCKFILE +elif test -e /etc/gentoo-release; then + . /sbin/functions.sh + _beginResult() { ebegin "$@"; } + _postResult() { :; } + success() { eend 0; } + passed() { eend 0; } + failure() { eend 1; } + lockfile=/var/lock/vservers/$LOCKFILE +else + _beginResult() { echo -n "$@..."; } + _postResult() { :; } + success() { echo .; } + passed() { echo .; } + failure() { echo ERROR; } + lockfile=/var/run/$LOCKFILE +fi + +function _endResult() +{ + local rc=$1 + case "$rc" in + (0) success;; + (2) passed; rc=0;; + (*) failure;; + esac + _postResult + return $rc +} diff --git a/scripts/vserver-wrapper b/scripts/vserver-wrapper index b9c9465..abab445 100755 --- a/scripts/vserver-wrapper +++ b/scripts/vserver-wrapper @@ -26,40 +26,7 @@ test -n "$MARK" || MARK=default : ${LOCKFILE:=vservers-$MARK} : ${NUMPARALLEL:=6} - -if test -e /etc/init.d/functions; then - . /etc/init.d/functions - _beginResult() { echo -n "$@ ..."; } - _postResult() { echo; } - lockfile=/var/lock/subsys/$LOCKFILE -elif test -e /etc/gentoo-release; then - . /sbin/functions.sh - _beginResult() { ebegin "$@"; } - _postResult() { :; } - success() { eend 0; } - passed() { eend 0; } - failure() { eend 1; } - lockfile=/var/lock/vservers/$LOCKFILE -else - _beginResult() { echo -n "$@ ..."; } - _postResult() { :; } - success() { echo .; } - passed() { echo .; } - failure() { echo ERROR; } - lockfile=/var/run/$LOCKFILE -fi - -function _endResult() -{ - local rc=$1 - case "$rc" in - (0) success;; - (2) passed; rc=0;; - (*) failure;; - esac - _postResult - return $rc -} +. "$_LIB_VSERVER_INIT_FUNCTIONS" function start() { diff --git a/sysv/Makefile-files b/sysv/Makefile-files index 18b5d13..54deb06 100644 --- a/sysv/Makefile-files +++ b/sysv/Makefile-files @@ -24,7 +24,8 @@ AM_INSTALLCHECK_STD_OPTIONS_EXEMPT += \ sysv_src_SCRPTS = sysv/rebootmgr \ sysv/vprocunhide \ sysv/vservers-default \ - sysv/vservers-legacy + sysv/vservers-legacy \ + sysv/util-vserver sysv_gen_SCRPTS = sysv/v_gated \ sysv/v_httpd \ sysv/v_named \ diff --git a/sysv/util-vserver b/sysv/util-vserver new file mode 100755 index 0000000..8e54016 --- /dev/null +++ b/sysv/util-vserver @@ -0,0 +1,88 @@ +#!/bin/bash +# +# util-vserver sets the path to vshelper and kills all guest processes +# +# chkconfig: 2345 10 90 +# description: Sets the path to vshelper and kills all guest processes + +: ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars} +test -e "$UTIL_VSERVER_VARS" || { + echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2 + exit 1 +} +. "$UTIL_VSERVER_VARS" + +LOCKFILE=util-vserver +. "$_LIB_VSERVER_INIT_FUNCTIONS" + + +function set_helper() +{ + local f="/proc/sys/kernel/vshelper" + if test -e "$f"; then + echo "$_VSHELPER" > "$f" + return 0 + else + return 2 + fi +} + +function kill_contexts() +{ + for xid in `ls -1 /proc/virtual`; do + test "$xid" = "info" -o "$xid" = "status" && continue + $_VATTRIBUTE --xid $xid --set --flag ~persistent + $_VKILL --xid $xid -s 15 + sleep 3 + $_VKILL --xid $xid -s 9 + done +} + +function start() +{ + _beginResult $"Setting path to vshelper" + set_helper + _endResult $? + local retval=$? + test "$retval" -ne 0 || touch "$lockfile" + return $retval +} + +function stop() +{ + # Stop all running, but non-default guests" + _beginResult $"Stopping all running guests" + $_START_VSERVERS -j 1 --all --stop + _endResult $? + local retval=$? + _beginResult $"Killing all running contexts" + kill_contexts + _endResult $? + $_RM -f "$lockfile" +} + +function restart() +{ + stop + start +} + +case "$1" in + start|stop|restart) $1;; + reload) ;; + condrestart) + test -f $lockfile && restart || : + ;; + status) + test -f $lockfile && { + echo $"/proc entries were fixed" + exit 0 + } + echo $"/proc entries are not fixed" + exit 1 + ;; + *) + echo "Usage: $0 {start|stop|reload|restart|condrestart|status}" + exit 2 + ;; +esac diff --git a/sysv/vprocunhide b/sysv/vprocunhide index 17a2cd4..285c1fb 100755 --- a/sysv/vprocunhide +++ b/sysv/vprocunhide @@ -14,36 +14,23 @@ test -e "$UTIL_VSERVER_VARS" || { $_VSERVER_INFO - FEATURE iattr || exit 0 -f=/etc/rc.d/init.d/functions -if test -e "$f"; then - . "$f" - lockfile=/var/lock/subsys/vprocunhide -else - success() { echo .; } - passed() { echo .; } - failure() { echo ERROR; } - lockfile=/var/run/vprocunhide -fi +LOCKFILE=vprocunhide +. "$_LIB_VSERVER_INIT_FUNCTIONS" function start() { - echo -n $"Fixing /proc entries visibility..." + _beginResult $"Fixing /proc entries visibility" $_VPROCUNHIDE - retval=$? - case "$retval" in - 0) success;; - 2) passed; retval=0;; - *) failure; - esac - echo + _endResult $? + local retval=$? test "$retval" -ne 0 || touch "$lockfile" return $retval } function stop() { - rm -f "$lockfile" + $_RM -f "$lockfile" } function restart() -- 1.8.1.5