Last active
October 23, 2016 22:35
-
-
Save yodeah/b150d3ac5f18486502741b614e55e184 to your computer and use it in GitHub Desktop.
aws startup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "START" | |
#you have to own this url and the url has to point to the server you are gonna run the script on | |
URL_TO_BE_CERTIFIED=beta2.daggersandsorcery.com | |
#you can add multiple urls/ips, separated by a space (api.daggersandsorcery.com www.api.daggersandsorcery.com) | |
ROUTE_THE_TRAFFIC_TO_THIS=api.daggersandsorcery.com | |
#So according to this your 5 8 * * 6 would run 8:05 every Saturday. | |
RENEW_CRONTAB="5 8 * * 6 sudo service nginx stop; cd /home/ubuntu/; sudo ./certbot-auto certonly --standalone -d "$URL_TO_BE_CERTIFIED" --email neandrw@gmail.com --renew-by-default --agree-tos --non-interactive; sudo service nginx start;" | |
#NGINX config file | |
CONFIG="user www-data;\n\n | |
worker_processes 4;\n\n | |
pid /run/nginx.pid;\n\n | |
\n\n | |
events {\n | |
worker_connections 768;\n | |
# multi_accept on;\n | |
}\n | |
\n\n | |
http {\n | |
upstream myapp1 {\n | |
server "$ROUTE_THE_TRAFFIC_TO_THIS";\n | |
}\n | |
\n\n | |
server{\n | |
listen 443 ssl;\n | |
server_name "$URL_TO_BE_CERTIFIED";\n | |
\n\n | |
ssl on;\n | |
ssl_certificate /etc/letsencrypt/live/"$URL_TO_BE_CERTIFIED"/fullchain.pem;\n | |
ssl_certificate_key /etc/letsencrypt/live/"$URL_TO_BE_CERTIFIED"/privkey.pem;\n | |
\n\n | |
location / {\n | |
proxy_pass http://myapp1;\n | |
}\n | |
} \n | |
}" | |
echo "CONFIG SET" | |
cd /home/ubuntu/ | |
wget https://dl.eff.org/certbot-auto | |
chmod a+x certbot-auto | |
./certbot-auto certonly --standalone -d "$URL_TO_BE_CERTIFIED" --email neandrw@gmail.com --renew-by-default --agree-tos --non-interactive | |
echo "CERTBOT INSTALL" | |
sudo apt-get install nginx | |
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup | |
rm /etc/nginx/nginx.conf | |
echo -en $CONFIG > /etc/nginx/nginx.conf | |
echo "NGINX INSTALL & CONFIG SETUP" | |
nginx -c /etc/nginx/nginx.conf -t | |
sudo service nginx restart | |
echo "NGINX CONFIG CHECK & RESTART" | |
rm /var/spool/cron/crontabs/root | |
echo "$RENEW_CRONTAB" > /var/spool/cron/crontabs/root | |
echo "CRONTAB UPDATED" | |
echo "DOONE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment