#!/bin/sh # this file normally resides in /usr/local/bin # very specific for our KULeuven setup tough, needs tuning for your systems! # # greetz, # harry DISKSIZE="3G" ARGS=4 E_BADARGS=65 test $# -ne $ARGS && echo -e "Usage: `basename $0` \nExample: `basename $0` test eth0 10.33.113.207 24" && exit $E_BADARGS # variables needed for ... ahm... stuff ;) CONTEXT=$((`cat /usr/local/etc/vservers/*/context | sort -n | tail -n1` + 1)) # check if there is a valid contextnumber if [ "$CONTEXT" -lt 2 ] then echo "no valid context number found, bailing out, very scared now!"; exit 1; fi NAME=$1 IF=$2 IP=$3 MASK=$4 # first some basic sanity checks if [ -b /dev/mapper/vservervg-${NAME}lv ] then echo "biiiiiig problem, logical volume allready exists, bailing out, very scared now!" exit 1; fi ping -c1 ${IP} > /dev/null test $? -eq 0 && echo "ip address in use, bailing out, very scared now!" && exit 1; if [ "${MASK}" -gt 32 ] || [ "${MASK}" -lt 0 ] then echo "netmask out of range, choose one between 0 and 32, bailing out, very scared now!" exit 1; fi # let's do this!!! echo -n "creating logical volume: ${NAME}lv ..." lvcreate -n ${NAME}lv -L ${DISKSIZE} vservervg test $? -ne 0 && echo "error creating logical volume!!!" && exit 1; echo "done" echo -n "creating reiserfs on ${NAME}vg ..." mkfs.reiserfs -q /dev/vservervg/${NAME}lv test $? -ne 0 && echo "error creating filesystem!!!" && exit 1; echo "done" echo -n "creating mountpoint: /vservers/${NAME} ..." mkdir /vservers/${NAME} test $? -ne 0 && echo "error creating mountpoint!!!" && exit 1; echo "done" echo -n "creating fstab entry for ${NAME} ..." echo "/dev/mapper/vservervg-${NAME}lv /vservers/${NAME} reiserfs defaults,attrs,noatime 0 2" >> /etc/fstab test $? -ne 0 && echo "error creating adding fstab entry!!!" && exit 1; echo "done" echo -n "mounting filesystem ..." mount /vservers/${NAME} test $? -ne 0 && echo "error mounting filesystem!!!" && exit 1; echo "done" echo -n "creating ${NAME} skeleton server ..." vserver ${NAME} build -m skeleton --context $CONTEXT --hostname ${NAME} --interface ${IF}:${IP}/${MASK} test $? -ne 0 && echo "error creating skeleton server!!!" && exit 1; echo "done" echo -n "setting cpu limits (25% of all), mem limits (1GB vmm, 512MB real) for ${NAME} ..." echo "sched_prio" > /usr/local/etc/vservers/${NAME}/flags; mkdir /usr/local/etc/vservers/${NAME}/sched; echo "1" > /usr/local/etc/vservers/${NAME}/sched/fill-rate; echo "4" > /usr/local/etc/vservers/${NAME}/sched/interval; echo "100" > /usr/local/etc/vservers/${NAME}/sched/tokens; echo "10" > /usr/local/etc/vservers/${NAME}/sched/tokens-min; echo "1000" > /usr/local/etc/vservers/${NAME}/sched/tokens-max; echo "0" > /usr/local/etc/vservers/${NAME}/sched/priority-bias; mkdir /usr/local/etc/vservers/${NAME}/rlimits; echo "262144" > /usr/local/etc/vservers/${NAME}/rlimits/rss.hard; echo "131072" > /usr/local/etc/vservers/${NAME}/rlimits/rss.soft; echo "4096" > /usr/local/etc/vservers/${NAME}/rlimits/nproc; echo "done" echo "Now copy the standard server from our config machine." echo "To start the vserver at boottime, issue the following command:" echo "echo default > /usr/local/etc/vservers/${NAME}/apps/init/mark" exit 0