Skip to content

Instantly share code, notes, and snippets.

@mkrupczak3
Created October 9, 2019 01:33
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 mkrupczak3/74ee47c6f5cc19a81469308f95dd5906 to your computer and use it in GitHub Desktop.
Save mkrupczak3/74ee47c6f5cc19a81469308f95dd5906 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# startup.sh
#
# Startup the nginx server. The server has to be active for the Let's Encrypt Certbot to
# register and install the certificates.
nginx -g "daemon on;"
# Checks that the SSL certificates are installed. If they are, renews any that are old, and
# installs them if not.
if [[ -d "/etc/letsencrypt/live/matthew.krupczak.org" ]]; then
if ! [[ -f "/etc/ssl/certs/dhparam.pem" ]]; then
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
fi
certbot renew --quiet
else
if ! [[ -f "/etc/ssl/certs/dhparam.pem" ]]; then
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
fi
if ! [[ -d "/etc/letsencrypt/live/matthew.krupczak.org" ]]; then
certbot --nginx -m matthew@krupczak.org --agree-tos --no-eff-email --redirect --expand -d matthew.krupczak.org
fi
fi
# Shuts down the daemonized nginx server and fires up one in the foreground.
nginx -s stop && nginx -g 'daemon off;'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment