4 VSERVERS_CONF=/etc/vservers
5 EXCLUDE_FILE="$VSERVERS_CONF/clone-exclude"
13 echo "Creates a new vserver with the specified name, which is a clone"
14 echo "from the vserver \`\`$TEMPLATE'' with some post-processing done."
19 IP_FILES="$VSERVERS_CONF/*/interfaces/*/ip"
22 if ! grep ^$IP$ $IP_FILES &>/dev/null; then
30 if [ ! "$#" -eq 1 ]; then
37 if ! echo $NAME | grep "^[a-zA-Z0-9-]*$" &>/dev/null; then
38 echo "Name can only contain alphanumerics and dashes"
42 HOST="$NAME/`hostname --fqdn`"
46 echo "No available ip address found, aborting"
50 echo "Creating vserver $NAME with address $IP..."
51 sudo vserver $NAME build -m clone --hostname $HOST --interface $INTERFACE:$IP/$NETMASK -- --source $TEMPLATE --exclude-from $EXCLUDE_FILE
53 echo "Vserver created, configuring..."
54 sudo vserver $NAME start
56 sudo vserver $NAME exec dpkg-reconfigure openssh-server
57 # Setup git - Add a branch for this vserver
58 sudo vserver $NAME exec git branch $NAME origin/$TEMPLATE
59 sudo vserver $NAME exec git checkout $NAME
60 # Remove the template branch, to prevent pushing it back later on
61 sudo vserver $NAME exec git branch -d $TEMPLATE
62 # Push our new branch upstream so it can be pushed with "git push" afterwards.
63 sudo vserver $NAME exec git push origin $NAME:$NAME
64 # Enable vhashify/vunify
65 sudo mkdir $VSERVER_CONF/$NAME/apps/vunify
66 sudo touch $VSERVER_CONF/$NAME/apps/vunify/dummy # For git
68 # Remove trailing slashes from the confdir. git only works when we're using
69 # relative paths and the cwd is / for some reason...
70 CONF_FOR_GIT=`echo $VSERVERS_CONF/$NAME | sed "s#^/*##"`
71 # Commit the configuration
72 (cd /; git add $CONF_FOR_GIT)
73 (cd /; git commit $CONF_FOR_GIT --edit --message "vserver: Add $NAME vserver configuration.")