Você não deveria ter que configurar nada. Qualquer recente instalação Debian / Ubuntu do certbot deve instalar um temporizador systemd e uma tarefa cron (e a tarefa cron só será executada se o systemd não estiver ativo, portanto você não executará ambos).
timer do systemd
Você pode verificar seus timers do sistema usando o comando systemctl list-timers (ou systemctl list-timers --all se você também quiser mostrar timers inativos). Algo parecido com isto:
% sudo systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES
Fri 2018-08-03 06:17:25 UTC 10h left Thu 2018-08-02 06:27:13 UTC 13h ago apt-daily-upgrade.timer apt-daily-upgrade.service
Fri 2018-08-03 11:43:29 UTC 15h left Thu 2018-08-02 16:54:52 UTC 3h 7min ago certbot.timer certbot.service
Fri 2018-08-03 12:44:58 UTC 16h left Thu 2018-08-02 19:14:58 UTC 47min ago apt-daily.timer apt-daily.service
Fri 2018-08-03 19:43:44 UTC 23h left Thu 2018-08-02 19:43:44 UTC 18min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Mon 2018-08-06 00:00:00 UTC 3 days left Mon 2018-07-30 00:00:09 UTC 3 days ago fstrim.timer fstrim.service
O cronômetro do certbot deve estar aqui /lib/systemd/system/certbot.timer e ele executará o comando especificado em /lib/systemd/system/certbot.service
certbot.timer executará o 'certbot.service às 12h e às 12h, após um atraso aleatório de até 12 horas (43.200 segundos).
# cat /lib/systemd/system/certbot.timer
[Unit]
Description=Run certbot twice daily
[Timer]
OnCalendar=*-*-* 00,12:00:00
RandomizedDelaySec=43200
Persistent=true
[Install]
WantedBy=timers.target
e certbot.service executarão o comando renew.
# cat /lib/systemd/system/certbot.service
[Unit]
Description=Certbot
Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html
Documentation=https://letsencrypt.readthedocs.io/en/latest/
[Service]
Type=oneshot
ExecStart=/usr/bin/certbot -q renew
PrivateTmp=true
trabalho cron
Como outros já mencionaram, há também uma tarefa cron instalada em /etc/cron.d/certbot :
# Eventually, this will be an opportunity to validate certificates
# haven't been revoked, etc. Renewal will only occur if expiration
# is within 30 days.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew
Isso está fazendo:
-
test -x /usr/bin/certbot -a \! -d /run/systemd/system - verifique se /usr/bin/certbot é um arquivo executável e se /run/systemd/system é não um diretório. Apenas continue para o próximo bit se essa verificação for bem-sucedida.
- A parte systemd da verificação efetivamente significa que, se o systemd estiver em execução, não execute o certbot a partir da tarefa cron - deixe isso para o cronômetro.
-
perl -e 'sleep int(rand(43200))' - dorme uma quantidade aleatória entre 0 segundos e 12 horas (43200 = 12 x 60 x 60).
-
certbot -q renew verificar seus certificados e renovar qualquer, se necessário. O sinalizador -q é "silencioso" - não produza nenhum resultado, a menos que haja um erro.
Eu estava originalmente confuso com a tarefa do cron porque ela não seria executada devido ao systemd, portanto, como o certbot seria executado? Eu encontrei a resposta em esta postagem do fórum , sobre a qual baseei essa resposta.