X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Fvserver.functions;h=4f2673794f1a5b2c408c64c1d186305af71e2d1f;hb=7bd540af89c36e0fc25d167f6c4893451b3331a3;hp=1563d9c8aabb81d9332bafae0daf7f972be6ce8f;hpb=7c6b9cbeda86c6b3422d4758f9dfdc95461b86fd;p=util-vserver.git diff --git a/util-vserver/scripts/vserver.functions b/util-vserver/scripts/vserver.functions index 1563d9c..4f26737 100644 --- a/util-vserver/scripts/vserver.functions +++ b/util-vserver/scripts/vserver.functions @@ -38,14 +38,18 @@ declare -a ENTER_SHELL=() declare -a OPTS_VCONTEXT_CREATE=() declare -a OPTS_VCONTEXT_MIGRATE=() -declare -a OPTS_VATTRIBUTE=() +declare -a OPTS_VATTRIBUTE=( --flag fakeinit ) declare -a OPTS_VSCHED=() +declare -a STOPCMD_PREPARE=() + declare -a VSERVER_EXTRA_CMDS=() VSHELPER_SYNC_TIMEOUT=30 USE_VNAMESPACE= INTERFACE_CMDS_IDX=0 +RUNLEVEL_START= +RUNLEVEL_STOP= _HAVE_INTERFACE_OPTIONS= _HAVE_CHBIND_OPTIONS= _NEED_VSHELPER_SYNC= @@ -59,7 +63,7 @@ SILENT_OPT= : ${VSERVER_NAME:=$(basename "$VSERVER_DIR")} -if test -e "$VSERVER_DIR"/noisy -o "$OPTION_VERBOSE"; then +if test -e "$VSERVER_DIR"/noisy -o -n "$OPTION_VERBOSE"; then SILENT_OPT= else SILENT_OPT='--silent' @@ -71,7 +75,7 @@ function _generateChbindOptions local i local bcast= - test "$_HAVE_INTERFACE_OPTIONS" || _generateInterfaceOptions "$vdir" + test -n "$_HAVE_INTERFACE_OPTIONS" || _generateInterfaceOptions "$vdir" local f=$vdir/interfaces/bcast getFileValue bcast "$f" @@ -156,12 +160,13 @@ function _generateCapabilityOptions function getEnterShell { local vdir=$1 + local shell_file ENTER_SHELL=() + + getFileValue ENTER_SHELL "$vdir"/shell "$CONFDIR"/.defaults/shell - getFileValue ENTER_SHELL "$vdir"/shell - - test "$ENTER_SHELL" || { + test -n "$ENTER_SHELL" || { local i for i in "/bin/bash -login" "/bin/sh -l" /bin/csh; do set -- $i @@ -182,8 +187,8 @@ function sendKillSequence while isCtxRunning "$ctx"; do test -z "$wait" || sleep "$wait" - $_VKILL -c "$ctx" ${1:+-s "$1"} - test "$2" || break + $_VKILL -c "$ctx" ${1:+-s "$1"} 2>/dev/null || : + test -n "$2" || break wait="$2" shift 2 done @@ -193,8 +198,6 @@ function _generateInitOptions { local vdir=$1 local cfgdir=$vdir/apps/init - local runlevel_start - local runlevel_stop local i f INITCMD_START=() @@ -202,28 +205,29 @@ function _generateInitOptions INITCMD_START_SYNC=() INITCMD_STOP_SYNC=() INITCMD_PREPARE=() + STOPCMD_PREPARE=() INITKILL_SEQ=( 15 5 9 ) CHCONTEXT_INIT_OPTS=() getFileValue INITSTYLE "$cfgdir"/style - getFileValue runlevel_start "$cfgdir"/runlevel - getFileValue runlevel_start "$cfgdir"/runlevel.start - getFileValue runlevel_stop "$cfgdir"/runlevel.stop + getFileValue RUNLEVEL_START "$cfgdir"/runlevel + getFileValue RUNLEVEL_START "$cfgdir"/runlevel.start + getFileValue RUNLEVEL_STOP "$cfgdir"/runlevel.stop getFileArray INITKILL_SEQ "$cfgdir"/killseq || : case x"$INITSTYLE" in (xsysv) - test "$runlevel_start" || runlevel_start=3 - test "$runlevel_stop" || runlevel_stop=6 + test -n "$RUNLEVEL_START" || RUNLEVEL_START=3 + test -n "$RUNLEVEL_STOP" || RUNLEVEL_STOP=6 for i in /etc/init.d/rc /etc/rc.d/rc; do test -x "$vdir/vdir/$i" || continue - INITCMD_START=( "$i" "$runlevel_start" ) - INITCMD_STOP=( "$i" "$runlevel_stop" ) + INITCMD_START=( "$i" "$RUNLEVEL_START" ) + INITCMD_STOP=( "$i" "$RUNLEVEL_STOP" ) done - INITCMD_PREPARE=( $_FAKE_RUNLEVEL "$runlevel_start" /var/run/utmp ) + INITCMD_PREPARE=( $_FAKE_RUNLEVEL "$RUNLEVEL_START" /var/run/utmp ) ;; (xplain) @@ -231,8 +235,8 @@ function _generateInitOptions INITCMD_STOP=( /sbin/init ) _IS_FAKEINIT=1 _NEED_VSHELPER_SYNC=1 - test -z "$runlevel_start" || INITCMD_START=( "${INITCMD_START[@]}" "$runlevel_start" ) - test -z "$runlevel_stop" || INITCMD_STOP=( "${INITCMD_STOP[@]}" "$runlevel_stop" ) + test -z "$RUNLEVEL_START" || INITCMD_START=( "${INITCMD_START[@]}" "$RUNLEVEL_START" ) + test -z "$RUNLEVEL_STOP" || INITCMD_STOP=( "${INITCMD_STOP[@]}" "$RUNLEVEL_STOP" ) ;; (xminit) @@ -241,8 +245,8 @@ function _generateInitOptions _IS_FAKEINIT=1 INITCMD_START_SYNC=( "$_INITSYNC_MINIT_START" "$vdir" ) _NEED_VSHELPER_SYNC=1 - test -z "$runlevel_start" || INITCMD_START=( "${INITCMD_START[@]}" "$runlevel_start" ) - test -z "$runlevel_stop" || INITCMD_STOP=( "${INITCMD_STOP[@]}" "$runlevel_stop" ) + test -z "$RUNLEVEL_START" || INITCMD_START=( "${INITCMD_START[@]}" "$RUNLEVEL_START" ) + test -z "$RUNLEVEL_STOP" || INITCMD_STOP=( "${INITCMD_STOP[@]}" "$RUNLEVEL_STOP" ) ;; (xgentoo) @@ -262,7 +266,7 @@ function _generateInitOptions getFileArray INITCMD_PREPARE "$cfgdir"/cmd.prepare || : - test "$OPTION_FORCE_SYNC" -o -e "$cfgdir"/sync || { + test -n "$OPTION_FORCE_SYNC" -o -e "$cfgdir"/sync || { INITCMD_START_SYNC=() INITCMD_STOP_SYNC=() _NEED_VSHELPER_SYNC= @@ -317,17 +321,6 @@ function _generateChcontextOptions read domainname <"$vdir"/uts/domainname || read domainname <"$vdir"/domainname || : } 2>/dev/null - ## LEGACY ALERT - test \( ! -e "$vdir"/hostname -o -e "$vdir"/uts/nodename \) -a \ - \( ! -e "$vdir"/domainname -o -e "$vdir"/uts/domainname \) || { - echo $"\ -The hostname is now configured in 'uts/nodename' but not in 'hostname' anymore; -the old way is not supported when using 2.6 kernel patches so it is strongly -recommended to move these files. - -The same applies to 'domainname' vs. 'uts/domainname'." >&2 - } - test -z "$S_CONTEXT" || ctx=$S_CONTEXT _generateCapabilityOptions "$vdir" @@ -353,7 +346,7 @@ function _generateScheduleOptions local f="$vdir"/schedule test -e "$f" || return 0 - local fill_rate interval tokens tokens_min tokens_max cpu_mask + local fill_rate interval tokens tokens_min tokens_max prio_bias { { read fill_rate && \ @@ -361,47 +354,47 @@ function _generateScheduleOptions read tokens && \ read tokens_min && \ read tokens_max && \ - read cpu_mask || cpu_mask= + read prio_bias || prio_bias= } <"$f" } 2>/dev/null - test "$cpu_mask" || { + test -n "$prio_bias" || { echo $"Bad content in '$f'; aborting..." >&2 false } OPTS_VSCHED=( --fill-rate "$fill_rate" --interval "$interval" \ --tokens "$tokens" --tokens_min "$tokens_min" \ - --tokens_max "$tokens_max" --cpu_mask "$cpu_mask" ) + --tokens_max "$tokens_max" --priority-bias "$prio_bias" ) } function _getInterfaceValue { - local val=$1 - local dflt=$2 + local _giv_val=$1 + local _giv_dflt=$2 shift 2 - local i - local tmp + local _giv_i + local _giv_tmp - for i; do - read tmp <"$i/$val" && break || : + for _giv_i; do + read _giv_tmp <"$_giv_i/$_giv_val" && break || : done 2>/dev/null - : ${tmp:=$dflt} - eval $val=\$tmp + : ${_giv_tmp:=$_giv_dflt} + eval $_giv_val=\$_giv_tmp } ## Usage: _transformMask2Prefix function _transformMask2Prefix { - local tmp=$2 + local _tm2p_tmp=$2 - test "$tmp" || { - $_MASK2PREFIX "$3" || tmp=$? + test -n "$_tm2p_tmp" || { + $_MASK2PREFIX "$3" || _tm2p_tmp=$? } - eval $1=\$tmp + eval $1=\$_tm2p_tmp return 0 } @@ -448,18 +441,21 @@ function _processSingleInterface _getInterfaceValue scope '' "$iface" "$iface/.." _getInterfaceValue mac '' "$iface" - test "$ip" || { echo $"Can not read ip for '$iface'" >&2; return 1; } - - test ! -e "$iface"/only_ip || { - ## LEGACY ALERT - echo $"The 'only_ip' flag for interface '$iface' is deprecated; use 'nodev' instead of" >&2 - unset dev + test -n "$ip" || { echo $"Can not read ip for '$iface'" >&2; return 1; } + test -n "$dev" -o -e "$iface"/nodev || { + echo $"No device specified for '$iface'" >&2 + return 1; } - test ! -e "$iface"/nodev || unset dev - test ! -e "$iface"/down || up= - - if test "$dev"; then + + test ! -e "$iface"/down || up= + + while true; do _transformMask2Prefix prefix "$prefix" "$mask" + INTERFACES=( "${INTERFACES[@]}" "$ip${prefix:+/$prefix}" ) + + test ! -e "$iface"/nodev || break + ## LEGACY ALERT + test ! -e "$iface"/only_ip || break case "$dev" in (*.*) @@ -468,7 +464,7 @@ function _processSingleInterface return 1 } test -f /proc/net/vlan || { - _addInterfaceCmd VCONFIG "${dev/./ }" + _addInterfaceCmd VCONFIG ${dev/./ } _addInterfaceCmd IP_ADDR 127.0.0.1/8 broadcast 127.255.255.255 dev "$dev" _addInterfaceCmd IP_LINK "$dev" $up } @@ -479,19 +475,20 @@ function _processSingleInterface _addInterfaceCmd IP_ADDR "$ip${prefix:+/$prefix}" broadcast ${bcast:-+} ${name:+label "$dev:$name"} dev "$dev" #_addInterfaceCmd IP_ROUTE "$ip${prefix:+/$prefix}" dev "$dev" _addInterfaceCmd IP_LINK "$dev" $up - elif ! test "$ctx"; then + elif ! test -n "$ctx"; then echo $"Using 'dummy' (indirect) for interface '$dev' requires a fixed context number; dynamic ctx are not supported" >&2 return 1 else - test "$mac" || _generateMac mac "$(basename $iface)" "$ctx" || return 1 + test -z "$mac" || _generateMac mac "$(basename $iface)" "$ctx" || return 1 _addInterfaceCmd MODPROBE dummy "$dev" _addInterfaceCmd IP_LINK dev dummy0 address "$mac" _addInterfaceCmd NAMEIF "$dev" "$mac" _addInterfaceCmd IP_ADDR "$ip${prefix:+/$prefix}" dev "$dev" test -z "$extip" || _addInterfaceCmd IPTABLES "$ip${prefix:+/$prefix}" ${name:+label "$dev:$name"} "$ctx" "$extip" fi - INTERFACES=( "${INTERFACES[@]}" "$ip${prefix:+/$prefix}" ) - fi + + break + done } ## Usage: _generateInterfaceOptions @@ -549,7 +546,7 @@ function enableInterfaces function disableInterfaces { - test "$_HAVE_INTERFACE_OPTIONS" || _generateInterfaceOptions "$1" + test -n "$_HAVE_INTERFACE_OPTIONS" || _generateInterfaceOptions "$1" local i=$INTERFACE_CMDS_IDX declare -a var @@ -589,6 +586,10 @@ function prepareInit { find var/run ! -type d -print0; \ find var/lock ! -type d -print0; } | xargs -0r $_CHROOT_RM ;; + plain) + $_CHROOT_RM .autofsck forcefsck 2>/dev/null || : + : | $_CHROOT_CAT fastboot 2>/dev/null || : + ;; minit) ;; esac @@ -596,18 +597,32 @@ function prepareInit popd >/dev/null } +## Usage: prepareInit +function prepareStop +{ + pushd "$1/vdir" >/dev/null + case "$INITSTYLE" in + (sysv) + export PREVLEVEL=$RUNLEVEL_START # required by Debian's initscripts + ;; + esac + "${STOPCMD_PREPARE[@]}" + popd >/dev/null +} + + function generateOptions { _generateInterfaceOptions "$1" - test "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$1" + test -n "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$1" _generateNiceCommand "$1" _generateInitOptions "$1" _generateChcontextOptions "$1" _generateScheduleOptions "$1" - if test "$_IS_FAKEINIT"; then + if test -n "$_IS_FAKEINIT"; then CHCONTEXT_INIT_OPTS=( --disconnect --flag fakeinit ) - OPTS_VCONTEXT_MIGRATE=( "${OPTS_VCONTEXT_MIGRATE[@]}" --fakeinit --disconnect ) + OPTS_VCONTEXT_MIGRATE=( "${OPTS_VCONTEXT_MIGRATE[@]}" --initpid --disconnect ) fi } @@ -616,8 +631,22 @@ function _mountVserverInternal local fstab="$1" test -e "$fstab" || return 0 shift - - "$@" $_SECURE_MOUNT -a --chroot "$vdir" --fstab "$fstab" + + pushd "$vdir" >/dev/null + "$@" $_SECURE_MOUNT -a --chroot --fstab "$fstab" --rootfs no + popd >/dev/null +} + +function mountRootFS +{ + local cfgdir=$1 + local vdir=$1/vdir + local fstab="$cfgdir"/fstab + + test -e "$fstab" || return 0 + pushd "$vdir" >/dev/null + $_SECURE_MOUNT -a --chroot --fstab "$fstab" --rootfs only -n + popd >/dev/null } function mountVserver @@ -628,7 +657,8 @@ function mountVserver local mtab_src test -e "$cfgdir"/fstab -o \ - -e "$cfgdir"/fstab.local || return 0 + -e "$cfgdir"/fstab.local -o \ + -e "$cfgdir"/fstab.remote || return 0 findObject -r mtab_src "$vdir"/apps/init/mtab "$CONFDIR"/.defaults/init/mtab "$PKGLIBDEFAULTDIR"/mtab /dev/null @@ -636,13 +666,14 @@ function mountVserver $_CHROOT_CAT /etc/mtab <"$mtab_src" popd >/dev/null - test "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$cfgdir" + test -n "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$cfgdir" test -z "$NAMESPACE_CLEANUP" || isAvoidNamespace "$cfgdir" || \ $_VNAMESPACE --cleanup - _mountVserverInternal "$cfgdir"/fstab $_CHBIND "${CHBIND_OPTS[@]}" + _mountVserverInternal "$cfgdir"/fstab _mountVserverInternal "$cfgdir"/fstab.local + _mountVserverInternal "$cfgdir"/fstab.remote $_CHBIND "${CHBIND_OPTS[@]}" isAvoidNamespace "$cfgdir" || \ $_SECURE_MOUNT --rbind -n "$vdir" "/" @@ -654,10 +685,10 @@ function _umountVserverInternal test -e "$fstab" || return 0 shift - tac "$fstab" | { + $_TAC "$fstab" | { is_ok=1 while read src dst tmp; do - test "$tmp" || continue + test -n "$tmp" || continue case x"$src" in (x\#*) continue;; esac @@ -665,7 +696,7 @@ function _umountVserverInternal "$@" $_EXEC_CD "$dst" $_UMOUNT -lfn . || is_ok= done - test "$is_ok" + test -n "$is_ok" } } @@ -678,14 +709,14 @@ function umountVserver isAvoidNamespace "$cfgdir" || return 0 test -e "$cfgdir"/fstab -o \ -e "$cfgdir"/fstab.local || return 0 - test "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$cfgdir" + test -n "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$cfgdir" pushd "$vdir/" >/dev/null || return 1 _umountVserverInternal "$cfgdir"/fstab.local || is_ok= _umountVserverInternal "$cfgdir"/fstab $_CHBIND "${CHBIND_OPTS[@]}" || is_ok= popd >/dev/null || return 1 - test "$is_ok" + test -n "$is_ok" } ## Usage: waitForSync @@ -700,13 +731,13 @@ function waitForSync local cfgdir=$1 local fifo=$2 - if test "$_NEED_VSHELPER_SYNC"; then + if test -n "$_NEED_VSHELPER_SYNC"; then $_VSHELPER_SYNC "$fifo" "$VSHELPER_SYNC_TIMEOUT" || \ warning $"\ A timeout or other error occured while waiting for the synchronization signal from vserver '$VSERVER_NAME'. The vserver will be killed nevertheless..." - elif test "${#INITCMD_STOP_SYNC[@]}" -ne 0; then + elif test -n "${#INITCMD_STOP_SYNC[@]}" -ne 0; then "${INITCMD_STOP_SYNC[@]}" || \ warning $"\ Stop-synchronization for vserver '$VSERVER_NAME' failed. The vserver @@ -743,6 +774,49 @@ function execScriptlets $start "$i" "$flavor" "$name" done - test -z "$already_handled" -o "$DONT_SKIP_DEFAULTS" || break + test -z "$already_handled" -o -n "$DONT_SKIP_DEFAULTS" || break done } + + +function sanityCheck +{ + declare -r cfgdir=$1 + + ! test -e "$cfgdir"/fstab.local || + warning $"\ +WARNING: 'fstab' will *not* be executed in the network context of the + vserver anymore. Therefore, 'fstab.local' has the same functionality + and is obsoleted. When you need the old behaviour, put the mounts + into 'fstab.remote'" + + ! test -e "$cfgdir"/hostname -a ! -L "$cfgdir"/hostname || + warning $"\ +WARNING: The hostname is now configured in 'uts/nodename' but not in + 'hostname'." + + ! test -e "$cfgdir"/domainname -a ! -L "$cfgdir"/domainname || + warning $"\ +WARNING: The domainname is now configured in 'uts/domainname' but not + in 'domainname'." >&2 + + + local i + for i in "$cfgdir"/interfaces/*/only_ip; do + if test -e "$i"; then + local iface + iface=${i##$cfgdir/interfaces/} + iface=${iface%%/only_ip} + warning $"\ +WARNING: The 'only_ip' flag for interface '$iface' is deprecated; use + 'nodev' instead of" + fi + done + + find "$cfgdir" -type f -exec "$_CHECK_UNIXFILE" '{}' ';' + + vshelper.doSanityCheck + + $_VSERVER_INFO - VERIFYCAP || + panic $"capabilities are not enabled in kernel-setup" +}