Skip to content

Instantly share code, notes, and snippets.

@romanbonapart
Created March 27, 2019 06:31
Show Gist options
  • Save romanbonapart/5384337e2021ead257aab7055535ba4b to your computer and use it in GitHub Desktop.
Save romanbonapart/5384337e2021ead257aab7055535ba4b to your computer and use it in GitHub Desktop.
Update HAProxy Lets Encrypt
#!/bin/bash
cert_name="generic_cert"
haproxy_cert_dir="/etc/haproxy/certs"
email="<your_email>"
domains=""
for domain in "$@"
do
domains+="-d $domain "
done
certbot certonly --standalone --agree-tos --non-interactive \
-m $email --preferred-challenges http \
--http-01-port 9785 --cert-name $cert_name \
--renew-with-new-domains --keep-until-expiring $domains
# Combine the certificate chain and private key and put it
# into the correct HAProxy directory
cd /etc/letsencrypt/live/$cert_name
cat fullchain.pem privkey.pem > "$haproxy_cert_dir/cert.pem"
echo "Reloading haproxy"
sudo systemctl reload haproxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment