From: Matthijs Kooijman Date: Sun, 7 Jun 2009 11:33:03 +0000 (+0200) Subject: vserver: Add new vserver to /etc/hosts on the host. X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fservers%2Fdrsnuggles.git;a=commitdiff_plain;h=31990270e259442c975ab3e7ef42c081b8c73671 vserver: Add new vserver to /etc/hosts on the host. Previously, this would only happen for /etc/hosts in the dns vserver. This commit also changes the configuration scheme for this hosts file updating to be a bit less generalized. --- diff --git a/usr/local/bin/vserver-create b/usr/local/bin/vserver-create index 820962a..10f6d39 100755 --- a/usr/local/bin/vserver-create +++ b/usr/local/bin/vserver-create @@ -14,12 +14,8 @@ IP_RANGE=10.42.0. INTERFACE=dummy0 # The netmask for the address NETMASK=24 -HOSTS_VSERVER=dns -# The hosts file to which an entry for the new vserver should be added. Can be -# left empty to not record the new vserver anywhere. -HOSTS_FILE=$VSERVERS_CONF/$HOSTS_VSERVER/vdir/etc/hosts -# Any extra commands to execute after creating the vserver -POST_EXEC="sudo vserver $HOSTS_VSERVER exec /usr/bin/killall -HUP dnsmasq" +# The DNS vserver gets a new entry in its /etc/hosts +DNS_VSERVER=dns function usage() { @@ -40,6 +36,11 @@ function find_ip() return 1 } +if [ "`id -u`" -eq 0 ]; then + echo "$0 should not be run as root, it will use sudo where appropriate" + exit 1 +fi + # Check arguments if [ ! "$#" -eq 1 ]; then usage @@ -86,10 +87,10 @@ CONF_FOR_GIT=`echo $VSERVERS_CONF/$NAME | sed "s#^/*##"` (cd /; git add $CONF_FOR_GIT) (cd /; git commit $CONF_FOR_GIT --edit --message "vserver: Add $NAME vserver configuration.") -if [ -n "$HOSTS_FILE" ]; then - sudo sh -c "echo '$IP $NAME' >> '$HOSTS_FILE'" -fi +# Add this new vserver to the hosts file in the dns vserver and in the host +for file in /etc/hosts "$VSERVERS_CONF/$DNS_VSERVER/vdir/etc/hosts"; do + sudo sh -c "echo '$IP $NAME' >> '$file'" +done -if [ -n "$POST_EXEC" ]; then - $POST_EXEC -fi +# Restart dnsmasq in the dns vserver +sudo vserver $DNS_VSERVER exec /usr/bin/killall -HUP dnsmasq"