X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=usr%2Flocal%2Fbin%2Fvserver-create;h=820962a4e0a947c32a762e1b73259352b2e94111;hb=b821f2dd223b5ca3b56ef45f856881c533c8303b;hp=b73f6a267976d9649190f5427afad970040df62d;hpb=7e7725d67f90afe2c534d8c4f79084373764ddaa;p=matthijs%2Fservers%2Fdrsnuggles.git diff --git a/usr/local/bin/vserver-create b/usr/local/bin/vserver-create index b73f6a2..820962a 100755 --- a/usr/local/bin/vserver-create +++ b/usr/local/bin/vserver-create @@ -1,11 +1,25 @@ #!/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 +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" function usage() { @@ -39,7 +53,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 @@ -47,7 +61,10 @@ if ! find_ip; then exit 1 fi; +echo "Creating vserver $NAME with address $IP..." sudo vserver $NAME build -m clone --hostname $HOST --interface $INTERFACE:$IP/$NETMASK -- --source $TEMPLATE --exclude-from $EXCLUDE_FILE + +echo "Vserver created, configuring..." sudo vserver $NAME start # Regen ssh keys sudo vserver $NAME exec dpkg-reconfigure openssh-server @@ -68,3 +85,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.") + +if [ -n "$HOSTS_FILE" ]; then + sudo sh -c "echo '$IP $NAME' >> '$HOSTS_FILE'" +fi + +if [ -n "$POST_EXEC" ]; then + $POST_EXEC +fi