# Souci avec cerbot renew via crontab

**URL:** <https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365>\
**Category:** Support Debian\
**Created:** [Juin 21, 2020, 9:50 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365 "2020-06-21T09:50:55Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![tchup](https://www.debian-fr.org/user_avatar/www.debian-fr.org/tchup/32/4415_2.png) [@tchup](https://www.debian-fr.org/u/tchup)\
**Post date:** [Juin 21, 2020, 9:50 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/1 "2020-06-21T09:50:55Z")

</div>

Bonjour à tous,  
j’ai installé (y a 3 mois) un certificat SSL Let’s Encrypt avec **certbox** sur Debian 9

`sudo apt-get install certbot python-certbot-apache`

Tout fonctionne sauf le renouvellement automatique malgré le fichier crontab :

```
root@debian:~# cat /etc/cron.d/certbot
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

```

Si je comprends bien… cette commande teste si /usr/bin/certbot est exécutable ET teste la NON présence du dossier /run/systemd/system pour exécuter le renouvellement.  
S’il y a **systemd** alors certbot a aussi configuré un timer.

```
systemctl list-timers -all
NEXT LEFT LAST PASSED UNIT ACTIVATES
Fri 2020-06-19 17:39:00 CEST 11min left Fri 2020-06-19 17:09:01 CEST 18min ago phpsessionclean.timer phpsessionclean.service
Sat 2020-06-20 03:50:16 CEST 10h left Fri 2020-06-19 06:08:57 CEST 11h ago apt-daily.timer apt-daily.service
Sat 2020-06-20 04:22:56 CEST 10h left n/a n/a certbot.timer certbot.service
Sat 2020-06-20 06:34:07 CEST 13h left Fri 2020-06-19 06:02:47 CEST 11h ago apt-daily-upgrade.timer apt-daily-upgrade.service
n/a n/a n/a n/a systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service

5 timers listed.

```

Pourquoi y a-t-il n/a ?  
Que faire pour corriger la situation ?  
Merci d’avance

---

<div class="post-metadata">

**Author:** ![anon70622873](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@anon70622873](https://www.debian-fr.org/u/anon70622873)\
**Post date:** [Juin 21, 2020, 10:55 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/2 "2020-06-21T10:55:13Z")

</div>

Bonjour,

Cela signifie que certbot.service n’a jamais été exécuté ou échoue (voir les logs dans /var/log/letsencrypt/letsencrypt.log ou avec journalctl)  
Il faut d’abord vérifier que le renouvellemnt manuel fonctionne :

```nohighlight
certbot --dry-run renew

```

Si c’est le cas, que donnent :

```nohighlight
systemctl status certbot.timer 

```

```nohighlight
ls -l /etc/systemd/system/timers.target.wants/

```

```nohighlight
cat /lib/systemd/system/certbot.timer

```

```nohighlight
cat /lib/systemd/system/certbot.service

```

---

<div class="post-metadata">

**Author:** ![tchup](https://www.debian-fr.org/user_avatar/www.debian-fr.org/tchup/32/4415_2.png) [@tchup](https://www.debian-fr.org/u/tchup)\
**Post date:** [Juin 21, 2020, 2:35 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/3 "2020-06-21T14:35:12Z")

</div>

merci pour ton message

```
root@debian:~# cat /var/log/letsencrypt/letsencrypt.log
(rien)

root@debian:~# systemctl status certbot.timer
● certbot.timer - Run certbot twice daily
   Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled)
   Active: active (waiting) since Tue 2020-03-17 23:02:39 CET; 3 months 4 days ago

juin 21 16:28:49 debian systemd[1]: certbot.timer: Adding 18min 37.445662s random time.
juin 21 16:28:54 debian systemd[1]: certbot.timer: Adding 11h 42min 48.083314s random time.
juin 21 16:28:59 debian systemd[1]: certbot.timer: Adding 1h 19min 39.916220s random time.
juin 21 16:29:04 debian systemd[1]: certbot.timer: Adding 4h 59min 3.871084s random time.
juin 21 16:29:09 debian systemd[1]: certbot.timer: Adding 1h 7min 59.207615s random time.
juin 21 16:29:14 debian systemd[1]: certbot.timer: Adding 9h 18min 2.616682s random time.
juin 21 16:29:19 debian systemd[1]: certbot.timer: Adding 10h 25min 2.891183s random time.
juin 21 16:29:24 debian systemd[1]: certbot.timer: Adding 6h 42min 26.420992s random time.
juin 21 16:29:29 debian systemd[1]: certbot.timer: Adding 4h 2min 53.782794s random time.
juin 21 16:29:34 debian systemd[1]: certbot.timer: Adding 8h 18min 14.589240s random time.

root@debian:~# ls -l /etc/systemd/system/timers.target.wants/
total 0
lrwxrwxrwx 1 root root 35 janv. 15 2019 apt-daily.timer -> /lib/systemd/system/apt-daily.timer
lrwxrwxrwx 1 root root 43 janv. 15 2019 apt-daily-upgrade.timer -> /lib/systemd/system/apt-daily-upgrade.timer
lrwxrwxrwx 1 root root 33 mars 17 23:02 certbot.timer -> /lib/systemd/system/certbot.timer
lrwxrwxrwx 1 root root 41 janv. 16 2019 phpsessionclean.timer -> /lib/systemd/system/phpsessionclean.timer

root@debian:~# 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

root@debian:~# 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

```

si je lance `certbot --dry-run renew` (et que ça renouvèle correctement le certificat) je devrais attendre 3 mois pour vérifier le fonctionnement du crontab ???

---

<div class="post-metadata">

**Author:** ![anon70622873](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@anon70622873](https://www.debian-fr.org/u/anon70622873)\
**Post date:** [Juin 21, 2020, 3:11 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/4 "2020-06-21T15:11:05Z")

</div>

Tout semble correct pour les commandes effectuées. Le problème ne provient donc probablement pas de cron ou systemd mais de la configuration des sites et des certificats.

Pour

> [@tchup](#):
>
> `certbot --dry-run renew`

cette commande va seulement simuler le renouvellement (dry-run) pour voir s’il fonctionne.

---

<div class="post-metadata">

**Author:** ![tchup](https://www.debian-fr.org/user_avatar/www.debian-fr.org/tchup/32/4415_2.png) [@tchup](https://www.debian-fr.org/u/tchup)\
**Post date:** [Juin 21, 2020, 4:05 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/5 "2020-06-21T16:05:51Z")

</div>

> [@anon70622873](#):
>
> certbot --dry-run renew

ok 😉

```
root@debian:~# certbot --dry-run renew
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/mon.domaine.fr.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator apache, Installer apache
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for mon.domaine.fr
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/mon.domaine.fr/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/mon.domaine.fr/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.

```

ça à l’air good pourtant !..  
et le fichier `/var/log/letsencrypt/letsencrypt.log` s’est remplie du debug

---

<div class="post-metadata">

**Author:** ![anon70622873](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@anon70622873](https://www.debian-fr.org/u/anon70622873)\
**Post date:** [Juin 21, 2020, 4:46 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/6 "2020-06-21T16:46:40Z")

</div>

Et bien pour mois tout est ok.  
Je ne vois donc pas d’où vient le problème 😕  
On va quand même regarder le résultat de :

```nohighlight
journalctl -u certbot --no-pager

```

mais cela ne devrait rien donner au vu des retours précédents.  
Le seul truc qui me chagrine c’est le délai aléatoire qui me semble être ajouté un peu trop souvent.

---

<div class="post-metadata">

**Author:** ![tchup](https://www.debian-fr.org/user_avatar/www.debian-fr.org/tchup/32/4415_2.png) [@tchup](https://www.debian-fr.org/u/tchup)\
**Post date:** [Juin 21, 2020, 5:10 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/7 "2020-06-21T17:10:28Z")

</div>

```
root@debian:~# journalctl -u certbot --no-pager
-- No entries --

```

😑

---

<div class="post-metadata">

**Author:** ![tchup](https://www.debian-fr.org/user_avatar/www.debian-fr.org/tchup/32/4415_2.png) [@tchup](https://www.debian-fr.org/u/tchup)\
**Post date:** [Juin 21, 2020, 5:26 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/8 "2020-06-21T17:26:17Z")

</div>

```
root@debian:~# systemctl status certbot-renewal.timer
Unit certbot-renewal.timer could not be found.

```

Je pense que ce n’est pas normal que certbot-renewal.timer ne soit pas trouvé ! 😶

---

<div class="post-metadata">

**Author:** ![anon70622873](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@anon70622873](https://www.debian-fr.org/u/anon70622873)\
**Post date:** [Juin 21, 2020, 5:39 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/9 "2020-06-21T17:39:17Z")

</div>

C’est normal.  
Je n’ai que certbot.service et certbot.timer sur mes serveurs et cela fonctionne très bien.  
Par contre tu peux regarder aussi :

```nohighlight
systemctl status certbot.service

```

---

<div class="post-metadata">

**Author:** ![tchup](https://www.debian-fr.org/user_avatar/www.debian-fr.org/tchup/32/4415_2.png) [@tchup](https://www.debian-fr.org/u/tchup)\
**Post date:** [Juin 21, 2020, 7:56 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/10 "2020-06-21T19:56:14Z")

</div>

ok sûrement un timer d’une ancienne version…

```
root@debian:~# systemctl status certbot.service
● certbot.service - Certbot
   Loaded: loaded (/lib/systemd/system/certbot.service; static; vendor preset: enabled)
   Active: inactive (dead)
     Docs: file:///usr/share/doc/python-certbot-doc/html/index.html
           https://letsencrypt.readthedocs.io/en/latest/

root@debian:~# systemctl start certbot.service

root@debian:~# systemctl status certbot.service
● certbot.service - Certbot
   Loaded: loaded (/lib/systemd/system/certbot.service; static; vendor preset: enabled)
   Active: inactive (dead) since Sun 2020-06-21 21:30:45 CEST; 9s ago
     Docs: file:///usr/share/doc/python-certbot-doc/html/index.html
           https://letsencrypt.readthedocs.io/en/latest/
  Process: 50472 ExecStart=/usr/bin/certbot -q renew (code=exited, status=0/SUCCESS)
 Main PID: 50472 (code=exited, status=0/SUCCESS)

juin 21 21:30:34 debian systemd[1]: Starting Certbot...
juin 21 21:30:45 debian systemd[1]: Started Certbot.

```

Et miracle ! le certificat du site a été renouvelé ! 🙂  
Une idée du pourquoi le service n’était pas démarré ???  
J’ai remarqué également que les certificats étaient visibles dans /var/log/letsencrypt/letsencrypt.log =\> pas grave ???

---

<div class="post-metadata">

**Author:** ![anon70622873](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@anon70622873](https://www.debian-fr.org/u/anon70622873)\
**Post date:** [Juin 22, 2020, 9:38 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/11 "2020-06-22T09:38:05Z")

</div>

> [@tchup](#):
>
> Une idée du pourquoi le service n’était pas démarré ???

Aucune idée, sauf erreur de ma part le service (certbot.service) aurait dû être lancé par le timer (certbot.timer).  
Il va maintenant falloir surveiller si la tâche de renouvellement se lance bien deux fois par jour.

---

<div class="post-metadata">

**Author:** ![tchup](https://www.debian-fr.org/user_avatar/www.debian-fr.org/tchup/32/4415_2.png) [@tchup](https://www.debian-fr.org/u/tchup)\
**Post date:** [Juin 22, 2020, 10:36 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/12 "2020-06-22T10:36:07Z")

</div>

Apparemment le cron et/ou le timer fonctionnent…  
mais peut-être pas normalement :

```
root@debian:~# tail -f /var/log/cron.log
[...]
Jun 22 12:00:01 debian CRON[58355]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:01:01 debian CRON[58362]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:02:01 debian CRON[58364]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:03:01 debian CRON[58370]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:04:01 debian CRON[58372]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:05:01 debian CRON[58374]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:06:01 debian CRON[58381]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:07:01 debian CRON[58387]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:08:01 debian CRON[58393]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:09:01 debian CRON[58399]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:10:01 debian CRON[58469]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:11:01 debian CRON[58479]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:12:01 debian CRON[58482]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:13:02 debian CRON[58488]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:14:01 debian CRON[58491]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:15:01 debian CRON[58497]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:16:01 debian CRON[58511]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:17:01 debian CRON[58515]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:18:01 debian CRON[58523]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:19:01 debian CRON[58525]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:20:01 debian CRON[58540]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:21:01 debian CRON[58542]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:22:01 debian CRON[58545]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:23:01 debian CRON[58551]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:24:01 debian CRON[58557]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:25:01 debian CRON[58567]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:26:01 debian CRON[58569]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:27:01 debian CRON[58572]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:28:01 debian CRON[58582]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:29:01 debian CRON[58584]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:30:01 debian CRON[58586]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:31:01 debian CRON[58588]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:32:01 debian CRON[58591]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)
Jun 22 12:33:01 debian CRON[58597]: (root) CMD (test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew)

```

toutes les minutes depuis 12h00 … 😔

---

<div class="post-metadata">

**Author:** ![anon70622873](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@anon70622873](https://www.debian-fr.org/u/anon70622873)\
**Post date:** [Juin 22, 2020, 10:45 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/13 "2020-06-22T10:45:53Z")

</div>

Non ce n’est pas normal, tu dois avoir une autre tâche cron quelque part qui se lance toutes les minutes.  
Je viens de remarquer aussi ceci dans ton retour de systemctl list-timers :

```auto
n/a n/a n/a n/a systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service

```

qui devrait être lancé au boot et une fois par jour.  
Est-ce que tu as modifié manuellement des unités systemd (service, timer ou autre) ?

---

<div class="post-metadata">

**Author:** ![tchup](https://www.debian-fr.org/user_avatar/www.debian-fr.org/tchup/32/4415_2.png) [@tchup](https://www.debian-fr.org/u/tchup)\
**Post date:** [Juin 22, 2020, 3:24 UTC](https://www.debian-fr.org/t/souci-avec-cerbot-renew-via-crontab/82365/14 "2020-06-22T15:24:42Z")

</div>

Je crois avoir trouvé… j’avais modifié le fichier crontab pendant mes tests :

```nohighlight
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew

```

avec une \* à la place du zéro de minutes 😅
