Skip to content

Instantly share code, notes, and snippets.

@StanGenchev
Created July 21, 2020 09:24
Show Gist options
  • Save StanGenchev/7e4afd3ad282d3f50e32e3b5462d32a3 to your computer and use it in GitHub Desktop.
Save StanGenchev/7e4afd3ad282d3f50e32e3b5462d32a3 to your computer and use it in GitHub Desktop.
Share and keep Let's Encrypt/Certbot certificates synchronized with your EMQX service.
#!/bin/sh
set -e
for domain in $RENEWED_DOMAINS; do
case $domain in
your.site.com)
EMQX_CERT_ROOT=/etc/emqx/certs/your.site
# Make sure the certificate and private key files are
# never world readable, even just for an instant while
# we're copying them into EMQX_CERT_ROOT.
umask 077
cp "$RENEWED_LINEAGE/cert.pem" "$EMQX_CERT_ROOT/cert.pem"
cp "$RENEWED_LINEAGE/privkey.pem" "$EMQX_CERT_ROOT/privkey.pem"
cp "$RENEWED_LINEAGE/chain.pem" "$EMQX_CERT_ROOT/chain.pem"
cp "$RENEWED_LINEAGE/fullchain.pem" "$EMQX_CERT_ROOT/fullchain.pem"
# Apply the proper file ownership and permissions for
# the daemon to read its certificate and key.
chown emqx:emqx "$EMQX_CERT_ROOT/cert.pem" \
"$EMQX_CERT_ROOT/privkey.pem" \
"$EMQX_CERT_ROOT/chain.pem" \
"$EMQX_CERT_ROOT/fullchain.pem"
chmod 400 "$EMQX_CERT_ROOT/cert.pem" \
"$EMQX_CERT_ROOT/privkey.pem" \
"$EMQX_CERT_ROOT/chain.pem" \
"$EMQX_CERT_ROOT/fullchain.pem"
systemctl restart emqx >/dev/null
;;
esac
done
# Test with:
# export RENEWED_DOMAINS="your.site.com" RENEWED_LINEAGE="/etc/letsencrypt/live/your.site.com" && /etc/letsencrypt/renewal-hooks/deploy/emqx.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment