|
| 1 | +## Pre-Hooks and Post-Hooks |
| 2 | + |
| 3 | +The Pre- and Post-Hooks of [acme.sh](https://github.com/acmesh-official/acme.sh/) are available through the corresponding environment variables. This allows to trigger actions just before and after certificates are issued (see [acme.sh documentation](https://github.com/acmesh-official/acme.sh/wiki/Using-pre-hook-post-hook-renew-hook-reloadcmd)) |
| 4 | + |
| 5 | +#### Pre-Hook |
| 6 | +This command will be run before certificates are issued. For example `echo 'start'`: |
| 7 | +```shell |
| 8 | +$ docker run --detach \ |
| 9 | + --name nginx-proxy-acme \ |
| 10 | + --volumes-from nginx-proxy \ |
| 11 | + --volume /var/run/docker.sock:/var/run/docker.sock:ro \ |
| 12 | + --volume acme:/etc/acme.sh \ |
| 13 | + --env "DEFAULT_EMAIL=mail@yourdomain.tld" \ |
| 14 | + --env "ACME_PRE_HOOK=echo 'start'" |
| 15 | + nginxproxy/acme-companion |
| 16 | +``` |
| 17 | + |
| 18 | +#### Post-Hook |
| 19 | +This command will be run after certificates are issued. For example `echo 'end'`: |
| 20 | +```shell |
| 21 | +$ docker run --detach \ |
| 22 | + --name nginx-proxy-acme \ |
| 23 | + --volumes-from nginx-proxy \ |
| 24 | + --volume /var/run/docker.sock:/var/run/docker.sock:ro \ |
| 25 | + --volume acme:/etc/acme.sh \ |
| 26 | + --env "DEFAULT_EMAIL=mail@yourdomain.tld" \ |
| 27 | + --env "ACME_POST_HOOK=echo 'end'" |
| 28 | + nginxproxy/acme-companion |
| 29 | +``` |
| 30 | + |
| 31 | +#### Verification: |
| 32 | +If you want to check wether the hook-command is delivered properly to [acme.sh](https://github.com/acmesh-official/acme.sh/), you should check `/etc/acme.sh/[EMAILADDRESS]/[DOMAIN]/[DOMAIN].conf`. |
| 33 | +The variable `Le_PreHook` contains the Pre-Hook-Command base64 encoded. |
| 34 | +The variable `Le_PostHook` contains the Pre-Hook-Command base64 encoded. |
| 35 | + |
| 36 | +#### Limitations |
| 37 | +* The commands that can be used in the hooks are limited to the commands available inside the **acme-companion** container. `curl` and `wget` are available, therefore it is possible to communicate with tools outside the container via HTTP, allowing for complex actions to be implemented outside or in other containers. |
| 38 | +* The hooks are general options, therefore **the actions for all certificates are the same**. |
| 39 | + |
| 40 | +#### Use-cases |
| 41 | +* Change some firewall rules just for the issuing process of the certificates, so the ports 80 and/or 443 don't have to be publicly reachable at all time. |
| 42 | +* Monitoring. |
0 commit comments