There’s no way to specify a per-domain renew hook. However, the script you provide has access to the $RENEWED_DOMAINS variable, which will contain a list of renewed domains. Your bash script could use this variable in an if (or case) statement and restart the relevant service depending on the value.
Here’s the full documentation for --renew-hook where this is mentioned:
--renew-hook RENEW_HOOK
Command to be run in a shell once for each
successfully renewed certificate.For this command, the
shell variable $RENEWED_LINEAGE will point to
theconfig live subdirectory containing the new certs
and keys; the shell variable $RENEWED_DOMAINS will
contain a space-delimited list of renewed cert domains
Thank you for your answer. I suspected that can do it by only bash script. Can you show me simple example how to use this variable in my own scipt, becouse I’m new in bash scripting.
for domain in $RENEWED_DOMAINS
do
if [ "$domain" = relevant-domain.example.com ]
then
echo "Performing the reload action"
# Command(s) to actually perform the reload action should be placed here
fi
done
If you want to put various actions in the same script, there is also elif, like
for domain in $RENEWED_DOMAINS
do
if [ "$domain" = first.example.com ]
then
echo "Performing the first action"
# Command(s) to actually perform the first action should be placed here
elif [ "$domain" = second.example.com ]
then
echo "Performing the second action"
# Command(s) to actually perform the second action should be placed here
fi
done
You can add more elif blocks like this to handle more cases. There are also potential ways to avoid reloading twice when you renew domain.com and www.domain.com, but the most correct ones probably entail learning more shell scripting.
@szakal, I’m glad that’s helpful to you. In a future version of Certbot, there will also be a way to specify a particular certficate to renew with certbot renew (instead of renewing all of them that are near expiry), which will be useful for testing things like this.