From 8c11f873cfb8928b4147cb364f3a8569db439beb Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Sun, 24 Jun 2018 16:50:05 -0700 Subject: [PATCH] building --- servers/ec2-ssl.sh | 3 ++- servers/init.sh | 42 +++++++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/servers/ec2-ssl.sh b/servers/ec2-ssl.sh index 337edcf5..0f641186 100644 --- a/servers/ec2-ssl.sh +++ b/servers/ec2-ssl.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 ## Domain for new SSL certificate LETSENCRYPT_HOST="status.balancebadge.io" @@ -17,4 +18,4 @@ sudo printf "\nexport LETSENCRYPT_HOST=$LETSENCRYPT_HOST\n" >> /root/.profile sudo printf "export LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL\n" >> /root/.profile source /home/ubuntu/.profile sudo /bin/bash -c "source /root/.profile" -LETSENCRYPT_HOST=$LETSENCRYPT_HOST LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL ./startup.sh +LETSENCRYPT_HOST=$LETSENCRYPT_HOST LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL /home/ubuntu/init.sh diff --git a/servers/init.sh b/servers/init.sh index 62300af2..d3794b50 100644 --- a/servers/init.sh +++ b/servers/init.sh @@ -1,19 +1,38 @@ #!/usr/bin/env bash cd /home/ubuntu -sudo rm -rf startup.sh -sudo curl -o startup.sh -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/hunterlong/statup/master/servers/startup.sh -sudo chmod +x startup.sh +source /home/ubuntu/.profile +sudo rm -rf startup.sh > /dev/null +sudo curl -o startup.sh -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/hunterlong/statup/master/servers/startup.sh > /dev/null +sudo chmod +x startup.sh > /dev/null +sudo rm -f docker-compose.yml > /dev/null + +EC2_ENDPOINT=$(curl -s http://169.254.169.254/latest/meta-data/public-hostname) +EC_IP=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4) -sudo rm -f docker-compose.yml if [ "$LETSENCRYPT_HOST" = "" ] then - sudo curl -o docker-compose.yml -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/hunterlong/statup/master/servers/docker-compose.yml + printf "\n Status Status Page on EC2\n" + printf "================================================================================================================\n" + printf "Point your domain's DNS records to one of these endpoints.\n" + printf " A => EC2 Server IP: $EC_IP \n" + printf "CNAME => EC2 Public DNS: $EC2_ENDPOINT\n" + printf "================================================================================================================\n" + sudo curl -o docker-compose.yml -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/hunterlong/statup/master/servers/docker-compose.yml > /dev/null else - sudo curl -o docker-compose.yml -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/hunterlong/statup/master/servers/docker-compose-ssl.yml + printf " \n\n\n\nDomain found for SSL certificate - $LETSENCRYPT_HOST\n" + printf "================================================================================================================\n" + printf "You must set the domains DNS records to point to this server!\n" + printf " EC2 Server IP: $EC_IP\n" + printf " EC2 Public DNS: $EC2_ENDPOINT\n" + printf "================================================================================================================\n" + printf " CNAME $LETSENCRYPT_HOST => $EC2_ENDPOINT (if not using Elastic IP)\n" + printf " A $LETSENCRYPT_HOST => $EC_IP (or use A record if you are using an Elastic IP)\n" + printf "================================================================================================================\n\n\n" + + sudo curl -o docker-compose.yml -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/hunterlong/statup/master/servers/docker-compose-ssl.yml > /dev/null fi sudo service docker start -sudo docker system prune -af if [ "$LETSENCRYPT_HOST" = "" ] then @@ -24,4 +43,13 @@ else sudo LETSENCRYPT_HOST=$LETSENCRYPT_HOST LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL docker-compose up -d fi +sudo docker system prune -af +logger "Status Process complete. IP: $EC_IP | DNS: $EC2_ENDPOINT\n" + +#sudo docker rm -f $(sudo docker ps -a -q) +#sudo docker rmi $(sudo docker images -q) +#rm -rf docker-compose.yml +#sudo rm -rf statup +#sudo rm startup.sh +#sudo service docker stop