#!/bin/sh
-TEMPLATE=template
+# The dir containing vserver configuration
VSERVERS_CONF=/etc/vservers
+# The vserver to use as a template
+TEMPLATE=template
+# A file containing files (or masks) to not copy from the template vserver.
EXCLUDE_FILE="$VSERVERS_CONF/clone-exclude"
+# The ip range to use for creating a new vserver. A number between 2 and 253
+# will be appended to this, until an address is found that is not used by
+# another vserver..
IP_RANGE=10.42.0.
+# The interface on which to create the vserver
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()
{
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
exit 1
fi
-HOST="$NAME/`hostname --fqdn`"
+HOST="$NAME.`hostname --fqdn`"
# Set the IP var
if ! find_ip; then
# 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"