#!/bin/sh # chkconfig: 345 98 10 # description: The vservers service is used to start and stop all # the virtual servers. USR_SBIN=/usr/sbin SHAREDPARTS="hda3 hda4" XVPARTS="/etc/vservers/vpartitions" # Print the vserver name in priority/alpha order sortserver(){ ( cd /etc/vservers for serv in *.conf do PRIORITY=100 . $serv printf "%03d %s\n" $PRIORITY `basename $serv .conf` done ) | sort $* | (while read a b; do echo $b; done) } startservers(){ echo "setting up vroots" xvroot=0 echo -n "" > /etc/vservers/vpartitions for parti in $SHAREDPARTS ; do echo " $parti -> vrsetup /dev/vroot/$xvroot /dev/$parti" echo "$parti:$xvroot" >> $XVPARTS vrsetup /dev/vroot/$xvroot /dev/$parti let xvroot++ done echo "activating context quota" cd /etc/vservers for name in `sortserver` do REALBLOCKDEVICE= S_CONTEXT= . $name.conf if [ ! -z $S_CONTEXT ] ; then if [ ! -z $REALBLOCKDEVICE ] ; then myvroot=`grep $REALBLOCKDEVICE $XVPARTS | cut -d : -f 2` cp -af /dev/vroot/$myvroot /vservers/$name/dev/hdv1 && \ echo "activating quota on $S_CONTEXT ($name::$myvroot)" && \ echo "cqhadd -v -x $S_CONTEXT /dev/vroot/$myvroot" && \ cqhadd -v -x $S_CONTEXT /dev/vroot/$myvroot fi fi done echo "Starting the virtual servers" cd /etc/vservers for name in `sortserver` do ONBOOT= . $name.conf if [ "$ONBOOT" = "yes" ] ; then $USR_SBIN/vserver $name start echo "+ + + + + + + + + + + + + + + + + + + + + + +" else echo virtual server $name not configured for on boot start fi done } BACKGROUND=off if [ -f /etc/vservers.conf ] ; then . /etc/vservers.conf fi # See how we were called. case "$1" in start) if [ "$BACKGROUND" = "yes" ] ; then startservers >/dev/tty8 /dev/tty8 & else startservers fi touch /var/lock/subsys/vservers ;; stop) echo "Stopping the virtual servers" cd /etc/vservers for name in `sortserver -r` do $USR_SBIN/vserver $name stop echo "+ + + + + + + + + + + + + + + + + + + + + + +" done echo "deactivating context quota" cd /etc/vservers for name in `sortserver` do REALBLOCKDEVICE= S_CONTEXT= . $name.conf if [ ! -z $S_CONTEXT ] ; then if [ ! -z $REALBLOCKDEVICE ] ; then myvroot=`grep $REALBLOCKDEVICE $XVPARTS | cut -d : -f 2` echo "deactivating quota on $S_CONTEXT ($name::$myvroot)" && \ echo "cqhrem -v -x $S_CONTEXT /dev/vroot/$myvroot" && \ cqhrem -v -x $S_CONTEXT /dev/vroot/$myvroot fi fi done xvroot=0 echo "removing vroots" for i in `cat /etc/vservers/vpartitions` ; do myvroot=`echo $i | cut -d : -f 2` myparti=`echo $i | cut -d : -f 1` echo " > vrsetup -d /dev/vroot/$myvroot /dev/$myparti" vrsetup -d /dev/vroot/$myvroot /dev/$myparti done rm -f /var/lock/subsys/vservers ;; restart) $0 stop $0 start ;; reload) echo Not implemented ;; status) cd /etc/vservers for serv in *.conf do ONBOOT=no name=`basename $serv .conf` . $serv echo -n ONBOOT=$ONBOOT " " $USR_SBIN/vserver $name running done ;; *) echo "Usage: vservers {start|stop|restart|reload|status}" exit 1 esac exit 0