first pass at a script to rename a vserver
Marc Fiuczynski [Mon, 19 Nov 2007 17:41:07 +0000 (17:41 +0000)]
scripts/vrename [new file with mode: 0755]

diff --git a/scripts/vrename b/scripts/vrename
new file mode 100755 (executable)
index 0000000..3786d4d
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/env bash
+#
+# vrename is used to rename an existing vserver guest A to B.
+# 
+#
+# Marc E. Fiuczynski <mef@cs.princeton.edu>
+# Copyright (C) 2007 The Trustees of Princeton University
+#
+# $Id:$
+#
+
+oname=$1
+nname=$2
+
+if [ -d "/etc/vservers/${nname}" ] ; then
+       echo "WARNING: vserver ${nname} already exists.  Aborting..."
+       exit -1
+fi
+if [ ! -d "/etc/vservers/${oname}" ] ; then
+       echo "WARNING: vserver ${oname} does not exists.  Aborting..."
+       exit -1
+fi
+
+[ -f /var/run/vservers/${oname} ] && vserver $oname stop
+
+dlist="/vservers /etc/vservers /etc/vservers/.defaults/cachebase /var/run/vservers /etc/vservers/.defaults/vdirbase"
+
+for dir in $dlist; do
+    if [ -d "${dir}/${oname}" ] ; then
+       mv ${dir}/${oname} ${dir}/${nname}
+    fi
+done
+
+# create new symlinks
+ln -nsf /etc/vservers/.defaults/cachebase/${nname} /etc/vservers/${nname}/cache 
+ln -nsf /etc/vservers/.defaults/vdirbase/${nname} /etc/vservers/${nname}/vdir  
+ln -nsf /var/run/vservers/${nname} /etc/vservers/${nname}/run   
+
+exit 0