Add some scripts to convert a legacy config to the new tree.
Daniel Hokka Zakrisson [Fri, 20 Jul 2007 16:31:29 +0000 (16:31 +0000)]
scripts/Makefile-files
scripts/convert-vserver-configs [new file with mode: 0644]
scripts/vserver
scripts/vserver.convert [new file with mode: 0644]

index 329286c..ab3efc2 100644 (file)
@@ -75,7 +75,8 @@ scripts_pkglib_src_SCRPTS =   scripts/pkgmgmt \
                                scripts/vservers.grabinfo.sh \
                                scripts/vshelper \
                                scripts/vsysvwrapper \
-                               scripts/vyum-worker
+                               scripts/vyum-worker \
+                               scripts/vserver.convert
 
 scripts_legacy_src_SCRPTS =    scripts/legacy/save_s_context \
                                scripts/legacy/vserver \
@@ -100,7 +101,8 @@ scripts_sbin_src_PRGS =             scripts/chbind \
                                scripts/vupdateworld \
                                scripts/vuseradd \
                                scripts/vuserdel \
-                               scripts/vyum
+                               scripts/vyum \
+                               scripts/convert-vserver-configs
 
 scripts_sbin_gen_PRGS =
 scripts_sbincfg_gen_DTA =
diff --git a/scripts/convert-vserver-configs b/scripts/convert-vserver-configs
new file mode 100644 (file)
index 0000000..786fa10
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+#
+# $Id$
+# Copyright (C) 2007 The Trustees of Princeton University
+#
+
+: ${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"
+
+for i in $__CONFDIR/*.conf; do
+    if test -r "$i"; then
+       vserver=`echo "$i" | sed "s@$__CONFDIR/@@;s@\.conf@@"`
+       echo "Processing '$vserver'"
+       if ! $_VSERVER "$vserver" convert; then
+           echo "ERROR: '$vserver' could not be converted" >&2
+       fi
+    fi
+done
+
+exit 0
index ebd105b..f4ad355 100755 (executable)
@@ -173,6 +173,9 @@ if test -n "$allow_legacy"; then
     test -d "$VSERVER_DIR" -o ! -e "$__CONFDIR/$vserver.conf" || do_legacy=1
 
     test -z "$do_legacy" || {
+       if test "$cmd" = "convert"; then
+           exec $__PKGLIBDIR/vserver.convert "$vserver"
+       fi
        echo $"WARNING: can not find configuration, assuming legacy method" >&2
        exec "$_VSERVER_LEGACY" "$@"
     }
@@ -282,6 +285,10 @@ case "$2" in
            exit 3
        fi
        ;;
+    (convert)
+       echo "Vserver '$vserver' is already converted"
+       exit 1
+       ;;
     (*)
        echo $"Usage: $0 <vserver> {start|stop|suexec|restart|condrestart|exec|enter|chkconfig|running|status|delete}" >&2
        exit 2
diff --git a/scripts/vserver.convert b/scripts/vserver.convert
new file mode 100644 (file)
index 0000000..fcb2774
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/bash
+#
+# $Id$
+# Copyright (C) 2007 The Trustees of Princeton University
+# 
+
+: ${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"
+
+if test "$#" -ne 1; then
+    echo $"Usage: $0 <guest>" >&2
+    exit 1
+fi
+
+NAME="$1"
+if ! test -r "$__CONFDIR/$NAME.conf" -a -d "$__DEFAULT_VSERVERDIR/$NAME"; then
+    echo $"$NAME does not exist." >&2
+    exit 1
+fi
+
+. "$__CONFDIR/$NAME.conf"
+
+set -e
+
+# build configuration directory
+vuseradd "$NAME"
+
+# copy old settings
+function copy()
+{
+    test -z "$1" && return 0
+    echo "$1" > "$__CONFDIR/$NAME/$2"
+}
+
+copy "$VS_WHITELISTED" whitelisted
+copy "$VS_DISK_MAX"    dlimits/0/space_total
+if test -n "$CPUSHARE" -a -z "$CPULIMIT"; then
+    CPULIMIT="$CPUSHARE"
+fi
+
+copy "$CPULIMIT"       sched/fill-rate2
+if test "$CPUGUARANTEED" -eq 1; then
+    copy "$CPULIMIT"   sched/fill-rate
+fi
+
+copy "$TASKLIMIT"      rlimits/nproc.hard
+copy "$MEMLIMIT"       rlimits/rss.hard
+for l in CPU RSS NPROC NOFILE MEMLOCK AS LOCKS SIGPENDING MSGQUEUE NSOCK OPENFD ANON SHMEM; do
+    for i in HARD SOFT MINIMUM; do
+       eval copy \"\$VS_${l}_${i}\" \"rlimits/`echo "${l}.${i}" | tr [A-Z] [a-z] | sed 's/minimum$/min/'`\"
+    done
+done
+
+copy "$S_CAPS"         bcapabilities
+
+exit 0