3 # The dir containing vserver configuration
4 VSERVERS_CONF=/etc/vservers
5 # The vserver to use as a template
7 # A file containing files (or masks) to not copy from the template vserver.
8 EXCLUDE_FILE="$VSERVERS_CONF/clone-exclude"
9 # The ip range to use for creating a new vserver. A number between 2 and 253
10 # will be appended to this, until an address is found that is not used by
13 # The interface on which to create the vserver
15 # The netmask for the address
21 echo "Creates a new vserver with the specified name, which is a clone"
22 echo "from the vserver \`\`$TEMPLATE'' with some post-processing done."
27 IP_FILES="$VSERVERS_CONF/*/interfaces/*/ip"
30 if ! grep ^$IP$ $IP_FILES &>/dev/null; then
38 if [ ! "$#" -eq 1 ]; then
45 if ! echo $NAME | grep "^[a-zA-Z0-9-]*$" &>/dev/null; then
46 echo "Name can only contain alphanumerics and dashes"
50 HOST="$NAME/`hostname --fqdn`"
54 echo "No available ip address found, aborting"
58 echo "Creating vserver $NAME with address $IP..."
59 sudo vserver $NAME build -m clone --hostname $HOST --interface $INTERFACE:$IP/$NETMASK -- --source $TEMPLATE --exclude-from $EXCLUDE_FILE
61 echo "Vserver created, configuring..."
62 sudo vserver $NAME start
64 sudo vserver $NAME exec dpkg-reconfigure openssh-server
65 # Setup git - Add a branch for this vserver
66 sudo vserver $NAME exec git branch $NAME origin/$TEMPLATE
67 sudo vserver $NAME exec git checkout $NAME
68 # Remove the template branch, to prevent pushing it back later on
69 sudo vserver $NAME exec git branch -d $TEMPLATE
70 # Push our new branch upstream so it can be pushed with "git push" afterwards.
71 sudo vserver $NAME exec git push origin $NAME:$NAME
72 # Enable vhashify/vunify
73 sudo mkdir $VSERVER_CONF/$NAME/apps/vunify
74 sudo touch $VSERVER_CONF/$NAME/apps/vunify/dummy # For git
76 # Remove trailing slashes from the confdir. git only works when we're using
77 # relative paths and the cwd is / for some reason...
78 CONF_FOR_GIT=`echo $VSERVERS_CONF/$NAME | sed "s#^/*##"`
79 # Commit the configuration
80 (cd /; git add $CONF_FOR_GIT)
81 (cd /; git commit $CONF_FOR_GIT --edit --message "vserver: Add $NAME vserver configuration.")