drafting add-site script with git pull

This commit is contained in:
Michiel de Jong 2014-10-17 15:34:28 +01:00
parent e604576990
commit 1abd501781
6 changed files with 44 additions and 18 deletions

View file

@ -0,0 +1 @@
k2.michiel.indiehosters.net, indiehosters.net, 3pp.io

View file

@ -0,0 +1,2 @@
/.*@somedomain.com/ person1@gmail.com, person2@hotmail.com
/michiel@somewhere-else.net/ me@forward.net

View file

@ -0,0 +1 @@
k2.michiel.indiehosters.net

21
deploy/add-site.sh Executable file
View file

@ -0,0 +1,21 @@
#!/bin/sh
if [ $# -ge 4 ]; then
SERVER=$1
DOMAIN=$2
PEMFILE=$3
GITREPO=$4
else
echo "Usage: sh ./deploy/add-site.sh server domain pemfile gitrepo [user]"
exit 1
fi
if [ $# -ge 5 ]; then
USER=$5
else
USER="core"
fi
echo "Adding $DOMAIN to $SERVER with cert from $PEMFILE"
echo "Remote user is $USER"
ssh $USER@$SERVER sudo mkdir -p /data/per-user/$DOMAIN/nginx/data
scp $PEMFILE $USER@$SERVER:/data/server-wide/haproxy/approved-certs/$DOMAIN.pem
ssh $USER@$SERVER sudo sh /data/indiehosters/scripts/activate-user.sh $DOMAIN nginx $GITREPO

View file

@ -2,15 +2,20 @@
if [ $# -ge 1 ]; then
SERVER=$1
else
echo "Usage: sh ./deploy/deploy.sh server [branch [user]]"
echo "Usage: sh ./deploy/deploy.sh server [folder [branch [user]]]"
exit 1
fi
if [ $# -ge 2 ]; then
FOLDER=$2
else
FOLDER="./data/"
fi
if [ $# -ge 3 ]; then
BRANCH=$2
else
BRANCH="master"
fi
if [ $# -ge 3 ]; then
if [ $# -ge 4 ]; then
USER=$3
else
USER="core"
@ -20,26 +25,13 @@ if [ -e ../orchestration/per-server/$SERVER/default-site ]; then
else
DEFAULTSITE=$SERVER
fi
echo "Hoster data folder is $FOLDER"
echo "Infrastructure branch is $BRANCH"
echo "Remote user is $USER"
echo "Default site is $DEFAULTSITE"
chmod -R go-w ../orchestration/deploy-keys
if [ -f ../orchestration/deploy-keys/authorized_keys ]; then
scp -r ../orchestration/deploy-keys $USER@$SERVER:.ssh
fi
scp $FOLDER $USER@$SERVER:/data
scp ./deploy/onServer.sh $USER@$SERVER:
ssh $USER@$SERVER sudo mkdir -p /var/lib/coreos-install/
scp ../infrastructure/cloud-config $USER@$SERVER:/var/lib/coreos-install/user_data
scp cloud-config $USER@$SERVER:/var/lib/coreos-install/user_data
ssh $USER@$SERVER sudo sh ./onServer.sh $BRANCH $DEFAULTSITE
cd ../orchestration/per-server/$SERVER/sites/
for i in * ; do
echo "setting up site $i as `cat $i` on $SERVER";
ssh $USER@$SERVER sudo mkdir -p /data/per-user/$i/
scp ../../../TLS/approved-certs/$i.pem $USER@$SERVER:/data/server-wide/haproxy/approved-certs/$i.pem
rsync -r ../../../../user-data/live/$SERVER/$i/ $USER@$SERVER:/data/per-user/$i/
ssh $USER@$SERVER sudo sh /data/infrastructure/scripts/activate-user.sh $i `cat $i`
done
# Restart the default site now that its data has been rsync'ed in place:
ssh $USER@$SERVER sudo systemctl restart nginx\@$DEFAULTSITE

View file

@ -1,5 +1,14 @@
#!/bin/bash -eux
mkdir -p /data/per-user/$1/$2/data
cd /data/per-user/$1/$2/data
if [ -e www-content ]; then
cd www-content
git pull
else
git clone $3 www-content
fi
# Start service for new site (and create the user)
systemctl enable $2@$1.service
systemctl start $2@$1.service