X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=usr%2Flocal%2Fbin%2Fvserver-create;h=10f6d3985a6744d26959da1fd9b528f8d4766394;hb=405f91392c2ac65dfe68d987303908e8b02a32f3;hp=7311ab185534a9b3367a162df1afbb502320ed2a;hpb=10284eae2f18c41fd231ab541f933835b8c1c362;p=matthijs%2Fservers%2Fdrsnuggles.git diff --git a/usr/local/bin/vserver-create b/usr/local/bin/vserver-create index 7311ab1..10f6d39 100755 --- a/usr/local/bin/vserver-create +++ b/usr/local/bin/vserver-create @@ -14,6 +14,8 @@ IP_RANGE=10.42.0. INTERFACE=dummy0 # The netmask for the address NETMASK=24 +# The DNS vserver gets a new entry in its /etc/hosts +DNS_VSERVER=dns function usage() { @@ -34,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 @@ -47,7 +54,7 @@ if ! echo $NAME | grep "^[a-zA-Z0-9-]*$" &>/dev/null; then exit 1 fi -HOST="$NAME/`hostname --fqdn`" +HOST="$NAME.`hostname --fqdn`" # Set the IP var if ! find_ip; then @@ -79,3 +86,11 @@ CONF_FOR_GIT=`echo $VSERVERS_CONF/$NAME | sed "s#^/*##"` # Commit the configuration (cd /; git add $CONF_FOR_GIT) (cd /; git commit $CONF_FOR_GIT --edit --message "vserver: Add $NAME vserver configuration.") + +# 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 + +# Restart dnsmasq in the dns vserver +sudo vserver $DNS_VSERVER exec /usr/bin/killall -HUP dnsmasq"