use customizable value for vserver-rootdir instead of hardcoded '/vservers'
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Thu, 30 Oct 2003 15:16:30 +0000 (15:16 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Thu, 30 Oct 2003 15:16:30 +0000 (15:16 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/branches/SYSCALL_SWITCH@325 94cd875c-1c1d-0410-91d2-eb244daf1a30

13 files changed:
util-vserver/scripts/Makefile-files
util-vserver/scripts/distrib-info
util-vserver/scripts/util-vserver-vars.subst
util-vserver/scripts/vrpm
util-vserver/scripts/vserver
util-vserver/scripts/vserver-copy
util-vserver/scripts/vservers.grabinfo.sh
util-vserver/scripts/vunify.old.sh
util-vserver/src/Makefile-files
util-vserver/src/rebootmgr.c
util-vserver/src/vunify.cc
util-vserver/sysv/Makefile-files
util-vserver/sysv/rebootmgr.subst

index e598dbc..c60205b 100644 (file)
@@ -53,7 +53,8 @@ scripts_GENSCRPTS     =  scripts/util-vserver-vars \
 scripts/%:             scripts/%.subst
                        @mkdir -p $$(dirname '$@')
                        sed -e 's!@'PKGLIBDIR'@!$(pkglibdir)!g; \
-                               s!@'SBINDIR'@!$(sbindir)!g' '$<' >'$@.tmp'
+                               s!@'SBINDIR'@!$(sbindir)!g; \
+                               s!@'VSERVERDIR'@!$(vserverdir)!g' '$<' >'$@.tmp'
                        @-chmod --reference='$<' '$@.tmp'
                        @-rm -f '$@'
                        mv '$@.tmp' '$@'
index a493ab3..5a35f5e 100755 (executable)
@@ -47,7 +47,7 @@ elif [ -d "$1" ] ; then
        DISTDIR=$1
        CHROOTCMD="$SBINDIR/chroot $DISTDIR"
 else
-       DISTDIR=/vservers/$1
+       DISTDIR=$VROOTDIR/$1
        CHROOTCMD="$SBINDIR/chroot $DISTDIR"
 fi
 KEY=$2
index 3e049ac..86d2214 100755 (executable)
@@ -47,7 +47,7 @@ else
        while [ $# -gt 0 -a "$1" != "--" ]
        do
                if [ "$1" = "ALL" ] ; then
-                       SERVERS=`cd /vservers && ls`
+                       SERVERS=`cd $VROOTDIR && ls`
                else
                        SERVERS="$SERVERS $1"
                fi
@@ -75,9 +75,9 @@ else
                                source $CTXFILE
                                CTXOPT="--ctx $S_CONTEXT"
                        fi
-                       #echo rpm --root /vservers/$serv $*
+                       #echo rpm --root $VROOTDIR/$serv $*
                        echo Updating server $serv
-                       $SBINDIR/chcontext --silent $CTXOPT rpm --root /vservers/$serv $*
+                       $SBINDIR/chcontext --silent $CTXOPT rpm --root $VROOTDIR/$serv $*
                done
                if [ "$UNIFY" = "yes" ] ; then
                        PACKAGES=
index 25d4555..0fb590b 100755 (executable)
@@ -60,14 +60,14 @@ umountproc()
 testperm()
 {
        return
-       PERM=`$USR_LIB_VSERVER/showperm /vservers/$1/..`
+       PERM=`$USR_LIB_VSERVER/showperm $VROOTDIR/$1/..`
        if [ "$PERM" != 000 ] ; then
                echo
                echo "**********************************************************"
-               echo /vservers/$1/.. has insecure permissions.
+               echo $VROOTDIR/$1/.. has insecure permissions.
                echo A vserver administrator may be able to visit the root server.
                echo To fix this, do
-               echo "  " chmod 000 /vservers/$1/..
+               echo "  " chmod 000 $VROOTDIR/$1/..
                echo do it anytime you want, even if vservers are running.
                echo "**********************************************************"
                echo
@@ -185,7 +185,7 @@ setipopt(){
 # Extract the initial runlevel from the vserver inittab
 get_initdefault()
 {
-       INITDEFAULT=`grep :initdefault /vservers/$1/etc/inittab | sed 's/:/ /g' | ( read a level b; echo $level)`
+       INITDEFAULT=`grep :initdefault $VROOTDIR/$1/etc/inittab | sed 's/:/ /g' | ( read a level b; echo $level)`
 }
 
 # Read the vserver configuration file, reusing the PROFILE value
@@ -205,7 +205,7 @@ usage()
 {
        echo vserver [ options ] server-name command ...
        echo
-       echo server-name is a directory in /vservers
+       echo server-name is a directory in $VROOTDIR
        echo
        echo The commands are:
        echo " build   : Create a virtual server by copying the packages"
@@ -275,24 +275,24 @@ if [ $# -lt 2 ] ; then
        usage
 elif [ "$2" = "build" ] ; then
        # Either the directory does not exist or is empty
-       NBSUB=`ls /vservers/$1 2>/dev/null | grep -v lost+found | wc -l` 
+       NBSUB=`ls $VROOTDIR/$1 2>/dev/null | grep -v lost+found | wc -l` 
        NBSUB=`expr $NBSUB`
        if [ "$NBSUB" != 0 ] ; then
-               echo Virtual server /vservers/$1 already exist
+               echo Virtual server $VROOTDIR/$1 already exist
        else
-               if [ ! -d /vservers ] ; then
-                       mkdir /vservers || exit 1
-                       chmod 000 /vservers
-                       echo Directory /vservers was created with permissions 000
+               if [ ! -d $VROOTDIR ] ; then
+                       mkdir $VROOTDIR || exit 1
+                       chmod 000 $VROOTDIR
+                       echo Directory $VROOTDIR was created with permissions 000
                fi
-               mkdir -p /vservers/$1 || exit 1
-               chmod 755 /vservers/$1
+               mkdir -p $VROOTDIR/$1 || exit 1
+               chmod 755 $VROOTDIR/$1
                if test "$UTIL_VSERVER_AVOID_COPY"; then
-                   mkdir -p /vservers/$1/{etc/rc.d/init.d,sbin,var/run,var/log}
+                   mkdir -p $VROOTDIR/$1/{etc/rc.d/init.d,sbin,var/run,var/log}
                else
-                   cp -ax /sbin /bin /etc /usr /var /lib /vservers/$1/. || exit 1
+                   cp -ax /sbin /bin /etc /usr /var /lib $VROOTDIR/$1/. || exit 1
                fi
-               cd /vservers/$1 || exit 1
+               cd $VROOTDIR/$1 || exit 1
                rm -fr lib/modules/*
                rm -f var/spool/mail/*
                rm -f `find var/run -type f`
@@ -330,7 +330,7 @@ elif [ "$2" = "build" ] ; then
                                *.bak|*~|functions|killall|halt|single)
                                        ;;
                                *)
-                                       #$USR_LIB_VSERVER/capchroot /vservers/$1 /sbin/chkconfig --level 2345 $serv off
+                                       #$USR_LIB_VSERVER/capchroot $VROOTDIR/$1 /sbin/chkconfig --level 2345 $serv off
                                        $0 --silent $1 chkconfig --level 2345 $serv off
                                        ;;
                                esac
@@ -346,7 +346,7 @@ elif [ "$2" = "build" ] ; then
                cp -a $USR_LIB_VSERVER/vreboot sbin/.
                ln -sf vreboot sbin/vhalt
 
-               echo Directory /vservers/$1 has been populated
+               echo Directory $VROOTDIR/$1 has been populated
                if [ ! -d /etc/vservers ] ; then
                        mkdir /etc/vservers
                        chmod 600 /etc/vservers
@@ -431,8 +431,8 @@ S_CAPS=""
 elif [ ! -f /etc/vservers/$1.conf ] ; then
        echo No configuration for this vserver: /etc/vservers/$1.conf
        exit 1
-elif [ ! -d /vservers/$1/. ] ; then
-       echo No directory for this vserver: /vservers/$1
+elif [ ! -d $VROOTDIR/$1/. ] ; then
+       echo No directory for this vserver: $VROOTDIR/$1
        exit 1
 elif [ "$2" = "start" ] ; then
        echo Starting the virtual server $1
@@ -449,7 +449,7 @@ elif [ "$2" = "start" ] ; then
                . /etc/vservers/$1.conf
                export PROFILE
                ifconfig_iproot $1
-               cd /vservers/$1 || exit 1
+               cd $VROOTDIR/$1 || exit 1
 
                if [ "$PROFILE" != "" ] ; then
                        echo export PROFILE=$PROFILE >etc/PROFILE
@@ -458,7 +458,7 @@ elif [ "$2" = "start" ] ; then
                rm -f `find var/run -type f`
                touch var/run/utmp
                rm -f  var/lock/subsys/*
-               mountproc /vservers/$1
+               mountproc $VROOTDIR/$1
                CTXOPT=
                HOSTOPT=
                DOMAINOPT=
@@ -467,7 +467,7 @@ elif [ "$2" = "start" ] ; then
                CAPS=
                get_initdefault $1
                STARTCMD="/etc/rc.d/rc $INITDEFAULT"
-               if [ -x /vservers/$1/etc/init.d/rc ] ; then
+               if [ -x $VROOTDIR/$1/etc/init.d/rc ] ; then
                        STARTCMD="/etc/init.d/rc $INITDEFAULT"
                fi
 
@@ -524,9 +524,9 @@ elif [ "$2" = "start" ] ; then
                fi
                #echo FLAGS=$FLAGS
                #echo CAPS=$CAPS
-               # We switch to /vservers/$1 now, because after the
-               # security context switch /vservers directory becomes a dead zone.
-               cd /vservers/$1
+               # We switch to $VROOTDIR/$1 now, because after the
+               # security context switch $VROOTDIR directory becomes a dead zone.
+               cd $VROOTDIR/$1
                IPOPT=`setipopt $IPROOT`
                export PATH=$DEFAULTPATH
                $NICECMD $CHBIND_CMD $SILENT $IPOPT --bcast $IPROOTBCAST \
@@ -574,13 +574,13 @@ elif [ "$2" = "stop" ] ; then
        then
                test -x /etc/vservers/$1.sh && /etc/vservers/$1.sh pre-stop $1
                ifconfig_iproot $1
-               cd /vservers/$1
-               mountproc /vservers/$1
+               cd $VROOTDIR/$1
+               mountproc $VROOTDIR/$1
                # The fakeinit flag tell us how to turn off the server
                get_initdefault $1
                export PREVLEVEL=$INITDEFAULT
                STOPCMD="/etc/rc.d/rc 6"
-               if [ -x /vservers/$1/etc/init.d/rc ] ; then
+               if [ -x $VROOTDIR/$1/etc/init.d/rc ] ; then
                        STOPCMD="/etc/init.d/rc 6"
                fi
                for f in $S_FLAGS dummy
@@ -603,7 +603,7 @@ elif [ "$2" = "stop" ] ; then
 
                calculateCaps $S_CAPS
 
-               cd /vservers/$1
+               cd $VROOTDIR/$1
                IPOPT=`setipopt $IPROOT`
                export PATH=$DEFAULTPATH
                $CHBIND_CMD $SILENT $IPOPT --bcast $IPROOTBCAST \
@@ -626,7 +626,7 @@ elif [ "$2" = "stop" ] ; then
        fi
        # We umount anyway, because "enter" establish the mount
        # but when you exit, the server is considered not running
-       umountproc /vservers/$1
+       umountproc $VROOTDIR/$1
        cd /
        test -x /etc/vservers/$1.sh && /etc/vservers/$1.sh post-stop $1
        ifconfig_iproot_off $1
@@ -652,9 +652,9 @@ elif [ "$2" = "suexec" ] ; then
                IPROOTDEV=
                readlastconf $1
                . /etc/vservers/$1.conf
-               cd /vservers/$1
+               cd $VROOTDIR/$1
                ifconfig_iproot $1
-               mountproc /vservers/$1
+               mountproc $VROOTDIR/$1
                PS1="[\u@vserver:$1 \W]"
                export PS1
                VSERVER=$1
@@ -696,7 +696,7 @@ elif [ "$2" = "suexec" ] ; then
                if $0 $VSERVER running >/dev/null
                then
                        . /var/run/vservers/$VSERVER.ctx
-                       cd /vservers/$VSERVER
+                       cd $VROOTDIR/$VSERVER
                        IPOPT=`setipopt $IPROOT`
                        export PATH=$DEFAULTPATH
                        $CHBIND_CMD $SILENT $IPOPT --bcast $IPROOTBCAST \
@@ -718,7 +718,7 @@ elif [ "$2" = "suexec" ] ; then
                                DOMAINOPT="--domainname $S_DOMAINNAME"
                        fi
                        mkdir -p /var/run/vservers
-                       cd /vservers/$VSERVER
+                       cd $VROOTDIR/$VSERVER
                        IPOPT=`setipopt $IPROOT`
                        export PATH=$DEFAULTPATH
                        $CHBIND_CMD $SILENT $IPOPT --bcast $IPROOTBCAST \
@@ -748,11 +748,11 @@ elif [ "$2" = "chkconfig" ] ; then
                LEVELS=( --level "$2" )
                shift 2
        fi
-       if [ $# != 2 -a ! -x /vservers/$VSERVER/sbin/chkconfig ] ; then
+       if [ $# != 2 -a ! -x $VROOTDIR/$VSERVER/sbin/chkconfig ] ; then
                echo Invalid argument, expected vserver name chkconfig [ --level nnn ] service on\|off
-       elif [ -x /vservers/$VSERVER/sbin/chkconfig ] ; then
+       elif [ -x $VROOTDIR/$VSERVER/sbin/chkconfig ] ; then
                exec $0 --silent $VSERVER exec /sbin/chkconfig "${LEVELS[@]}" "$@"
-       elif [ -x /vservers/$VSERVER/usr/sbin/update-rc.d ] ; then
+       elif [ -x $VROOTDIR/$VSERVER/usr/sbin/update-rc.d ] ; then
                if [ "$2" = "on" -o "$2" = "start" ] ; then
                        $0 --silent $VSERVER exec /usr/sbin/update-rc.d -f $1 remove >/dev/null
                        exec $0 --silent $VSERVER exec /usr/sbin/update-rc.d $1 start 80 2 3 4 5 . stop 20 0 1 6 . >/dev/null
index 321cfda..31cd055 100755 (executable)
@@ -99,7 +99,7 @@ flag a vserver can even be operationally moved to different hardware within
 seconds.
 
 The -i and -d flags can be used to minimally reconfigure the destination
-vserver (rewrites /etc/vservers/newname.conf and /vservers/newname/etc/hosts)
+vserver (rewrites /etc/vservers/newname.conf and $VROOTDIR/newname/etc/hosts)
 
 Options:
        -h, --help              this help
@@ -143,7 +143,7 @@ rsh=(false)
 colon=":"
 domain=""
 ip=""
-vsroot="/vservers"
+vsroot=$VROOTDIR
 
 if [ $# -eq 0 ]; then  # Script invoked with no command-line args?
        usage
index 21de103..930d3a1 100644 (file)
@@ -25,7 +25,7 @@ test -e "$UTIL_VSERVER_VARS" || {
 }
 . "$UTIL_VSERVER_VARS"
 
-cd /vservers
+cd $VROOTDIR
 for vserv in *
 do
        if [ -f /etc/vservers/$vserv.conf ] ; then
index 50c960e..dde50b8 100755 (executable)
 # administrators can't upgrade package as they see fit, since the
 # files are immutable. On the other end, just unifying glibc is probably
 # a win.
+: ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars}
+test -e "$UTIL_VSERVER_VARS" || {
+    echo "Can not find util-vserver installation; aborting..."
+    exit 1
+}
+. "$UTIL_VSERVER_VARS"
+
 if [ $# = 0 ] ; then
        echo vunify [ --undo ] ref-vserver vservers -- packages
 else
@@ -61,7 +68,7 @@ else
                        echo No package specified >&2
                        exit 1
                else
-                       if [ ! -d /vservers/$ref/. ] ; then
+                       if [ ! -d $VROOTDIR/$ref/. ] ; then
                                echo No vserver $ref >&2
                                exit 1
                        else
@@ -73,7 +80,7 @@ else
                                echo Extracting list of file to unify in $tmpfile
                                for pkg in $*
                                do
-                                       /vservers/$ref/bin/rpm --root /vservers/$ref -ql --dump $pkg | \
+                                       $VROOTDIR/$ref/bin/rpm --root $VROOTDIR/$ref -ql --dump $pkg | \
                                        while read path size mtime md5 \
                                                mode owner group isconfig isdoc rdev symlink
                                        do
@@ -88,22 +95,22 @@ else
                                                echo Unifying server $serv
                                                cat $tmpfile | while read file
                                                do
-                                                       if [ ! -d /vservers/$ref/$file -a ! -L /vservers/$ref/$file ] ; then
-                                                               ln -f /vservers/$ref/$file /vservers/$serv/$file
+                                                       if [ ! -d $VROOTDIR/$ref/$file -a ! -L $VROOTDIR/$ref/$file ] ; then
+                                                               ln -f $VROOTDIR/$ref/$file $VROOTDIR/$serv/$file
                                                        fi
                                                done
                                                cat $tmpfile | while read file
                                                do
-                                                       chattr +i /vservers/$ref/$file
+                                                       chattr +i $VROOTDIR/$ref/$file
                                                done
                                        else
                                                echo Differencing server $serv
                                                cat $tmpfile | while read file
                                                do
-                                                       chattr -i /vservers/$ref/$file
-                                                       if [ ! -d /vservers/$ref/$file ] ; then
-                                                               rm -f /vservers/$serv/$file
-                                                               cp -a /vservers/$ref/$file /vservers/$serv/$file
+                                                       chattr -i $VROOTDIR/$ref/$file
+                                                       if [ ! -d $VROOTDIR/$ref/$file ] ; then
+                                                               rm -f $VROOTDIR/$serv/$file
+                                                               cp -a $VROOTDIR/$ref/$file $VROOTDIR/$serv/$file
                                                        fi
                                                done
                                        fi
index e7fe495..4633f71 100644 (file)
@@ -59,7 +59,7 @@ src_parserpmdump_SOURCES      =  src/parserpmdump.c
 src_readlink_SOURCES           =  src/readlink.c
 
 src_rebootmgr_SOURCES          =  src/rebootmgr.c
-src_rebootmgr_CPPFLAGS         =  $(AM_CPPFLAGS) -DSBINDIR=\"$(sbindir)\"
+src_rebootmgr_CPPFLAGS         =  $(AM_CPPFLAGS) -DSBINDIR=\"$(sbindir)\" -DVROOTDIR=\"$(vserverdir)\"
 
 src_reducecap_SOURCES          =  src/reducecap.c
 src_reducecap_LDADD            =  lib/libvserver.a
@@ -75,6 +75,7 @@ src_vserver_stat_SOURCES      =  src/vserver-stat.c
 src_vserver_stat_LDADD         =  lib/libvserver.a
 
 src_vunify_SOURCES             =  src/vunify.cc src/vutil.cc
+src_vunify_CPPFLAGS            =  $(AM_CPPFLAGS) -DVROOTDIR=\"$(vserverdir)\"
 src_vcheck_SOURCES             =  src/vcheck.cc src/vutil.cc
 
 #install-data-hook:            $(DESTDIR)$(pkglibdir)/setattr
index 3e5f5c2..43964bc 100644 (file)
@@ -66,7 +66,7 @@ static int rebootmgr_opensocket (const char *vname)
        int ret = -1;
        char sockn[PATH_MAX];
        int fd =  socket (AF_UNIX,SOCK_STREAM,0);
-       sprintf (sockn,"/vservers/%s/dev/reboot",vname);
+       sprintf (sockn,"%s/%s/dev/reboot",VROOTDIR, vname);
        unlink (sockn);
        if (fd == -1){
                fprintf (stderr,"Can't create a unix domain socket (%s)\n"
index 0faa03b..58d37c1 100644 (file)
@@ -204,8 +204,8 @@ class file_unifier{
        {}
        void operator()(const string &file)
        {
-               string refpath = "/vservers/" + ref_server + file;
-               string dstpath = "/vservers/" + target_server + file;
+               string refpath = VROOTDIR "/" + ref_server + file;
+               string dstpath = VROOTDIR "/" + target_server + file;
                if (debug) cout << "Unify " << refpath << " -> " << dstpath << endl;
                struct stat st;
                if (stat(refpath.c_str(),&st)==-1){
index c1aaf13..bef36f4 100644 (file)
@@ -47,7 +47,9 @@ sysv_CFG              =  sysv/vservers.conf
 sysv/%:                        sysv/%.subst
                        @mkdir -p $$(dirname '$@')
                        sed -e 's!/usr/lib/util-vserver!$(pkglibdir)!g; \
-                               s!^USR_SBIN=/usr/sbin$$!USR_SBIN=$(sbindir)!g' '$<' >'$@.tmp'
+                               s!^USR_SBIN=/usr/sbin$$!USR_SBIN=$(sbindir)!g; \
+                                s!^VROOTDIR=/vservers$$!VROOTDIR=$(vserverdir)!g; \
+                              ' '$<' >'$@.tmp'
                        if cmp -s '$<' '$@.tmp'; then \
                                cp -p '$<' '$@'; \
                        else \
index a526dd8..edd5a70 100755 (executable)
@@ -6,7 +6,7 @@
 # processname: rebootmgr
 # config: /etc/vservers
 
-
+VROOTDIR=/vservers
 USR_SBIN=/usr/sbin
 PIDFILE=/var/run/rebootmgr.pid
 # See how we were called.
@@ -18,7 +18,7 @@ case "$1" in
        for serv in *.conf
        do
                serv=`basename $serv .conf`
-               if [ -d /vservers/$serv ] ; then
+               if [ -d $VROOTDIR/$serv ] ; then
                        VSERVERS="$VSERVERS $serv"
                fi
        done