X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=scripts%2Fvserver.functions;h=be6e8138a76fd98589f743621924e3df151a0233;hb=899eb82a3219589a6748a6112e74a990a5accaec;hp=0f812d40200691ae02d12f931761aa52c2191401;hpb=2ccb6aff8218b761cab25da6a5fda09baf602871;p=util-vserver.git diff --git a/scripts/vserver.functions b/scripts/vserver.functions index 0f812d4..be6e813 100644 --- a/scripts/vserver.functions +++ b/scripts/vserver.functions @@ -42,6 +42,7 @@ declare -a OPTS_VCONTEXT_MIGRATE=() declare -a OPTS_VCONTEXT_ENTER=() declare -a OPTS_VATTRIBUTE=( --flag fakeinit ) declare -a OPTS_VSCHED=() +declare -a OPTS_ENV=() declare -a STOPCMD_PREPARE=() @@ -252,6 +253,11 @@ function _generateInitOptions getFileValue RUNLEVEL_STOP "$cfgdir"/runlevel.stop getFileArray INITKILL_SEQ "$cfgdir"/killseq || : + findFile _gio_env "$cfgdir"/environment \ + "$__CONFDIR"/.defaults/apps/init/environment \ + "$__PKGLIBDEFAULTDIR"/environment + getFileArray OPTS_ENV "$_gio_env" || : + case x"$INITSTYLE" in (xrescue) INITCMD_START=( "${INITCMD_RESCUE[@]}" ) @@ -293,7 +299,24 @@ function _generateInitOptions ;; (xgentoo) - panic "init-style '$INITSTYLE' is no longer supported; please use plain instead; aborting";; + INITCMD_START=( /lib/rcscripts/sh/init-vserver.sh ) + INITCMD_STOP=( /sbin/rc shutdown ) + + pushd "$vdir"/vdir &>/dev/null + basever=$($_CHROOT_SH cat /etc/gentoo-release | $_AWK '{print $5}') + popd &>/dev/null + + basemaj=${basever/.*} + basemin=${basever#*.} + basemin=${basemin/.*} + + test "$basemaj" -lt 1 -o "$basemin" -lt 13 && \ + panic "\ +Using init-style 'gentoo' requires >=baselayout-1.13 inside the vserver! + +Your vserver ($(basename "$vdir")) seems to have baselayout-$basever, +please use 'plain' init-style instead!" + ;; (x) ;; (*) panic "Unknown init-style '$INITSTYLE'; aborting";; @@ -527,7 +550,11 @@ function _processSingleInterface echo -e $"VLAN device-name used, but vlan subsystem not enabled.\nTry to execute 'modprobe 8021q' before starting the vservers" >&2 return 1 } - test -f /proc/net/vlan -o -e "$iface"/novlandev || { + test -e "$iface/vlandev" \ + -o \( -e "$iface/../vlandev" -a ! -e "$iface/novlandev" \) \ + -o \( -e "$__CONFDIR/.defaults/interfaces/vlandev" \ + -a ! -e "$iface/novlandev" \ + -a ! -e "$iface/../novlandev" \) && { _addInterfaceCmd VCONFIG $vlan_info } fi @@ -689,6 +716,54 @@ function generateOptions fi } +function addtoCPUSET +{ + local vdir=$1 + local cpuset + local f="$vdir"/cpuset + local i + local configured=0 + + test -d "$f" || return 0 + test -e "$f"/name || return 0 + + read cpuset < "$f"/name + test -e "$f"/nocreate || { + test -d /dev/cpuset/"$cpuset" || mkdir /dev/cpuset/"$cpuset" || configured=1 + for i in cpus mems cpu_exclusive mem_exclusive virtualized; do + if test -e "$f"/"$i"; then + cat "$f"/"$i" >/dev/cpuset/"$cpuset"/"$i" || { + configured=1 + break + } + fi + done + } + + echo $$ >/dev/cpuset/"$cpuset"/tasks || configured=1 + if [ "$configured" -ne 0 ]; then + warning $"\ +WARNING: Failed to create or CPUSET \"$cpuset\" does not exist! Not using it!" >&2 + rmdir /dev/cpuset/"$cpuset" 2>/dev/null || : + return 0 + fi +} + +function removeCPUSET +{ + local vdir=$1 + local cpuset + local f="$vdir"/cpuset + + test -d "$f" || return 0 + test -e "$f"/name || return 0 + + read cpuset < "$f"/name + test -e "$f"/nocreate || { + rmdir /dev/cpuset/"$cpuset" 2>/dev/null || : + } +} + function _mountVserverInternal { local fstab="$1" @@ -742,13 +817,13 @@ function mountVserver test -n "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$cfgdir" - test -z "$NAMESPACE_CLEANUP" || isAvoidNamespace "$cfgdir" || \ - $_VNAMESPACE --cleanup - _mountVserverInternal "$cfgdir"/fstab _mountVserverInternal "$cfgdir"/fstab.local _mountVserverInternal "$cfgdir"/fstab.remote $_CHBIND "${CHBIND_OPTS[@]}" + isNamespaceCleanup "$cfgdir" && \ + _namespaceCleanup "$cfgdir" + isAvoidNamespace "$cfgdir" || \ $_SECURE_MOUNT --rbind -n "$vdir" "/" } @@ -1100,3 +1175,42 @@ function saveDiskLimits _saveSingleDiskLimit "$vdir" "$dlimit" done } + +function _namespaceCleanup +{ + local vdir="$1" + local root=$($_VSERVER_INFO "$1" VDIR 1) + local -a list + local -a skip + local tmp + + getFileArray skip "$vdir"/namespace-cleanup-skip \ + "$__CONFDIR"/.defaults/namespace-cleanup-skip || : + + # these are things that have to be accessible post-cleanup + for tmp in "$root" "$__SBINDIR" "$__PKGLIBDIR" "$vdir" \ + "$__PKGSTATEDIR" "${skip[@]}"; do + while test -n "$tmp"; do + list=( "${list[@]}" "$tmp" ) + tmp="${tmp%/*}" + done + done + + local -a list_umount + while read dev path opts; do + test -n "$path" || continue + for i in "$root" /dev /proc; do + test "${path#$i}" != "$path" && continue 2 + done + for i in "${list[@]}" /; do + test "$path" = "$i" && continue 2 + done + # unmount them in reverse order so mounts further down the tree get unmounted first + list_umount=( "$path" "${list_umount[@]}" ) + done < /proc/mounts + # separate loop to avoid races while reading /proc/mounts + for i in "${list_umount[@]}"; do + $_UMOUNT -l -n "$i" + done +} +