Skip to content

Instantly share code, notes, and snippets.

@orrisroot
Last active October 20, 2021 08:23
Show Gist options
  • Save orrisroot/2f9a5012f6e75efc88bb3470446ad413 to your computer and use it in GitHub Desktop.
Save orrisroot/2f9a5012f6e75efc88bb3470446ad413 to your computer and use it in GitHub Desktop.
Service restart script for Let's encrypt renewal hooks (deploy)
#!/bin/bash
SERVICE_NAME=postfix
SERVICE_DOMAINS=example.com
IS_ACTIVE=$(systemctl is-active ${SERVICE_NAME})
if [ "${IS_ACTIVE}" != "active" ]; then
exit 0
fi
RESTART=0
for rdomain in ${RENEWED_DOMAINS}; do
for sdomain in ${SERVICE_DOMAINS}; do
if [ "${rdomain}" = "${sdomain}" ]; then
RESTART=1
break 2
fi
done
done
if [ ${RESTART} -eq 0 ]; then
exit 0
fi
# SSL certificate for ${SERVICE_NAME} was modified.
systemctl restart ${SERVICE_NAME}
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment