Skip to content

Instantly share code, notes, and snippets.

@yodeah
Last active October 23, 2016 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yodeah/b150d3ac5f18486502741b614e55e184 to your computer and use it in GitHub Desktop.
Save yodeah/b150d3ac5f18486502741b614e55e184 to your computer and use it in GitHub Desktop.
aws startup script
#!/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