I have such setup:
-
/var/apps/deploy.sh
script which does something and sends a email notification -
cli.ini
containsrenew-hook = /var/apps/deploy.sh
It works OK but there is a small problem: I have to put email addresses into deploy.sh
. If only addresses could come from somewhere else I’d put the script into a git repository and use it on all servers without any changes.
The best option would be the same cli.ini
since I have to manually set the renew hook there anyways.
As I see it I can set environments variables for hooks in cli.ini
like
renew-hook = MY_EMAIL=kaka@shino.bu /var/apps/deploy.sh # Quoting required mby?
disable-hook-validation = True
I tried running the execute()
function from certbot/certbot/hooks.py
manually with commands like MY_EMAIL=kaka@shino.bu /var/apps/deploy.sh
and $MY_EMAIL
was set in deploy.sh
but it looks ugly to me putting vars into commands. Besides ugliness it breaks some logging logic in execute()
because of
def execute(shell_cmd):
"""Run a command.
:returns: `tuple` (`str` stderr, `str` stdout)"""
# universal_newlines causes Popen.communicate()
# to return str objects instead of bytes in Python 3
cmd = Popen(shell_cmd, shell=True, stdout=PIPE,
stderr=PIPE, universal_newlines=True)
out, err = cmd.communicate()
base_cmd = os.path.basename(shell_cmd.split(None, 1)[0]) # <========= THIS
if out:
logger.info('Output from %s:\n%s', base_cmd, out)
if cmd.returncode != 0:
logger.error('Hook command "%s" returned error code %d',
shell_cmd, cmd.returncode)
if err:
logger.error('Error output from %s:\n%s', base_cmd, err)
return (err, out)
Is there some other way to set environmental variables for hooks in cli.ini
? Mby there is some undocumented cli option like --set-hook-env X=Y
?