mosquitto-copy.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/sh
  2. # This is an example deploy renewal hook for certbot that copies newly updated
  3. # certificates to the Mosquitto certificates directory and sets the ownership
  4. # and permissions so only the mosquitto user can access them, then signals
  5. # Mosquitto to reload certificates.
  6. # RENEWED_DOMAINS will match the domains being renewed for that certificate, so
  7. # may be just "example.com", or multiple domains "www.example.com example.com"
  8. # depending on your certificate.
  9. # Place this script in /etc/letsencrypt/renewal-hooks/deploy/ and make it
  10. # executable after editing it to your needs.
  11. # Set which domain this script will be run for
  12. MY_DOMAIN=example.com
  13. # Set the directory that the certificates will be copied to.
  14. CERTIFICATE_DIR=/etc/mosquitto/certs
  15. if [ "${RENEWED_DOMAINS}" = "${MY_DOMAIN}" ]; then
  16. # Copy new certificate to Mosquitto directory
  17. cp ${RENEWED_LINEAGE}/fullchain.pem ${CERTIFICATE_DIR}/server.pem
  18. cp ${RENEWED_LINEAGE}/privkey.pem ${CERTIFICATE_DIR}/server.key
  19. # Set ownership to Mosquitto
  20. chown mosquitto: ${CERTIFICATE_DIR}/server.pem ${CERTIFICATE_DIR}/server.key
  21. # Ensure permissions are restrictive
  22. chmod 0600 ${CERTIFICATE_DIR}/server.pem ${CERTIFICATE_DIR}/server.key
  23. # Tell Mosquitto to reload certificates and configuration
  24. pkill -HUP -x mosquitto
  25. fi