From 1abd50178165efa0c71710d55903f349cb56cee5 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Fri, 17 Oct 2014 15:34:28 +0100 Subject: [PATCH] drafting add-site script with git pull --- data/server-wide/postfix/destinations | 1 + data/server-wide/postfix/forwards | 2 ++ data/server-wide/postfix/hostname | 1 + deploy/add-site.sh | 21 ++++++++++++++++++++ deploy/deploy.sh | 28 ++++++++++----------------- scripts/activate-user.sh | 9 +++++++++ 6 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 data/server-wide/postfix/destinations create mode 100644 data/server-wide/postfix/forwards create mode 100644 data/server-wide/postfix/hostname create mode 100755 deploy/add-site.sh diff --git a/data/server-wide/postfix/destinations b/data/server-wide/postfix/destinations new file mode 100644 index 0000000..71d164b --- /dev/null +++ b/data/server-wide/postfix/destinations @@ -0,0 +1 @@ +k2.michiel.indiehosters.net, indiehosters.net, 3pp.io diff --git a/data/server-wide/postfix/forwards b/data/server-wide/postfix/forwards new file mode 100644 index 0000000..d185aa6 --- /dev/null +++ b/data/server-wide/postfix/forwards @@ -0,0 +1,2 @@ +/.*@somedomain.com/ person1@gmail.com, person2@hotmail.com +/michiel@somewhere-else.net/ me@forward.net diff --git a/data/server-wide/postfix/hostname b/data/server-wide/postfix/hostname new file mode 100644 index 0000000..cc7fd8b --- /dev/null +++ b/data/server-wide/postfix/hostname @@ -0,0 +1 @@ +k2.michiel.indiehosters.net diff --git a/deploy/add-site.sh b/deploy/add-site.sh new file mode 100755 index 0000000..882b64f --- /dev/null +++ b/deploy/add-site.sh @@ -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 diff --git a/deploy/deploy.sh b/deploy/deploy.sh index 085d7fd..8119c88 100755 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -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 diff --git a/scripts/activate-user.sh b/scripts/activate-user.sh index 86c114a..2f82079 100755 --- a/scripts/activate-user.sh +++ b/scripts/activate-user.sh @@ -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