About this list Date view Thread view Subject view Author view Attachment view

From: Dennis Roos (dennis_at_intouch.net)
Date: Mon 24 Jan 2005 - 10:54:34 GMT


On Mon, 2005-01-24 at 11:38, Timo Müller wrote:
> Hi !!
> I need a Script, which catched the IP-Adress form my vServer and
> write it to the sshd_conf behind ListenAddress !!
>
> Can anybody write my that little Script ??
For the old school config style (NAME.sh/NAME.conf), I use the script
below to replace all instances of TEMPLATE in the vserver's /etc/
directory and do some additional configuration.

There are a _lot_ of known limitations/assumptions here, but modify it
to suit your needs ;)

---%<--- /etc/vservers/NAME.sh --->%---
#!/bin/bash
###########
# Self configuring vserver startup script :)
###########
# TODO:
# vlan / ip route configuration
# hosts file magic
# set root password to a boring and known default
###########

SVRNAME=`echo $0 | rev | cut -d / -f 1 | cut -d . -f 2 | rev`
if [ "`grep -v template ${MYHOSTNAME}`" == "" ]; then
        ### Safety precautions ###
        echo "*[ERROR]*"
        echo "You probably forgot to edit /etc/vservers/${SVRNAME}.conf"
        echo "Bailing out!"
        exit 1
fi

MYHOSTNAME=`grep -v "\#" /etc/vservers/${SVRNAME}.conf | grep S_HOSTNAME
| cut -d = -f 2`
MYNETDEV=`grep -v "\#" /etc/vservers/${SVRNAME}.conf | grep IPROOT | cut
-d \" -f 2 | cut -d : -f 1`
MYVLAN=`echo ${MYNETDEV} | grep "\." | cut -d . -f 2`
SVRADDR=`ip addr show ${MYNETDEV} label ${MYNETDEV}:${SVRNAME} secondary
| awk '{print $2}'`
SVRIP=`echo $SVRADDR | cut -d / -f 1`
SVRMASK=`echo $SVRADDR | cut -d / -f 2`

UpdateVSConfig() {
        echo -n "Updating configs: "
        ### Update configs
        cd /vservers/$SVRNAME/

        for file in `grep -lr TEMPLATE etc`; do
                echo -n "$file,"
                mv $file $file.old
                sed -e "s/TEMPLATE/${SVRIP}/" $file.old > $file
                rm $file.old
        done
}

case $1 in
pre-start)
        echo "**** CONFIGURATION FOUND: ****"
        echo "Servername: ${SVRNAME}"
        echo "Serveraddr: ${SVRADDR}/${SVRMASK}"
        echo "Hostname : ${MYHOSTNAME}"
        echo "Networkdev: ${MYNETDEV}"
        echo "******************************"

        ### Update config files
        UpdateVSConfig

        ### Gentoo specifics
        if [ -d /vservers/${SVRNAME}/usr/portage 2> /dev/null ]; then
                mount -o bind,ro /usr/portage
/vservers/${SVRNAME}/usr/portage
                rm -f /vservers/${SVRNAME}/var/run/init.d/started/*
        fi

        # Enable (parts of) the proc filesystem
        # (useful and harmless: cpuinfo, slabinfo, interrupts)
        vproc -e /proc/cmdline
        vproc -e /proc/loadavg
        vproc -e /proc/meminfo
        vproc -e /proc/mounts
        vproc -e /proc/stat
        vproc -e /proc/uptime
        #(vproc -e /proc/version)

        echo "${SVRNAME}" > /vservers/${SVRNAME}/etc/.HOSTNAME
        ;;
post-start)
        ### Generic default route
        if [ "${MYVLAN}" == "" ]; then
                ip route add default via XXX.XXX.XXX.XXX
        else
                ### IpTables per host default route
                ip route add XXX.XXX.XXX.XXX/XX dev ethY.${MYVLAN} table
${MYVLAN}
                ip route add default via XXX.XXX.XXX.XXX dev
ethY.{$MYVLAN} table ${MYVLAN}
                ip rule add from XXX.XXX.XXX.XXX/XX table ${MYVLAN}
        fi
        ;;

pre-stop)
        ;;
post-stop)
        ### Gentoo specifics
        if [ -d /vservers/${SVRNAME}/usr/portage 2> /dev/null ]; then
                umount /vservers/$SVRNAME/usr/portage
        fi
        ;;
esac
---%<--- /etc/vservers/NAME.sh --->%---

> Thanx
Enjoy ;)

-- 
Regards,
Dennis Roos

Network Engineer InTouch N.V. Middenweg 76 1097 BS Amsterdam Tel: +31 (0)20 6752060 Fax: +31 (0)20 6758429

_______________________________________________ Vserver mailing list Vserver_at_list.linux-vserver.org http://list.linux-vserver.org/mailman/listinfo/vserver


About this list Date view Thread view Subject view Author view Attachment view
[Next/Previous Months] [Main vserver Project Homepage] [Howto Subscribe/Unsubscribe] [Paul Sladen's vserver stuff]
Generated on Mon 24 Jan 2005 - 10:55:02 GMT by hypermail 2.1.3