Collision de jobs cron.daily et cron.hourly

Salut
Dans un fonctionnement avec cron et anacron, les jobs sont lancés selon les paramètres dans /etc/crontab et /etc/anacrontab
Ce qui fait:

  • cron.hourly à chaque heure + 17 mn
  • cron.dally à T boot + 5 mn

Et donc j’ai booté par hasard a 10 H 12 mn et les jobs sont rentrés en concurrence. :rage:

j’ai donc modifié les deux tables à ma façon pour que seul anacron gère tout

  • /etc/crontab (ne lance plus aucun jobs )

# m h dom mon dow user	command
17 *	* * *	root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.hourly )
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
  • /etc/anacrontab (lance tous les jobs avec un délai de 15 mn entre chaque)
# These replace cron's entries
0 50	cron.hourly 	run-parts --report /etc/cron.hourly
1	5	cron.daily	run-parts --report /etc/cron.daily
7	20	cron.weekly	run-parts --report /etc/cron.weekly
@monthly 35	cron.monthly	run-parts --report /etc/cron.monthly
root@debian:/# 
  • Déja c’est plus lisible au niveau du journal
root@debian:/# journalctl -xb | grep cron
nov. 04 18:05:02 debian systemd[1]: Started Trigger anacron every hour.
-- Subject: L'unité (unit) anacron.timer a terminé son démarrage
-- L'unité (unit) anacron.timer a terminé son démarrage, avec le résultat RESULT.
-- Subject: L'unité (unit) cron.service a terminé son démarrage
-- L'unité (unit) cron.service a terminé son démarrage, avec le résultat RESULT.
nov. 04 18:05:02 debian systemd[1]: Started Run anacron jobs.
-- Subject: L'unité (unit) anacron.service a terminé son démarrage
-- L'unité (unit) anacron.service a terminé son démarrage, avec le résultat RESULT.
nov. 04 18:05:02 debian cron[596]: (CRON) INFO (pidfile fd = 3)
nov. 04 18:05:03 debian cron[596]: (CRON) INFO (Running @reboot jobs)
nov. 04 18:05:03 debian anacron[601]: Anacron 2.3 started on 2017-11-04
nov. 04 18:05:03 debian anacron[601]: Will run job `cron.daily' in 5 min.
nov. 04 18:05:03 debian anacron[601]: Will run job `cron.weekly' in 20 min.
nov. 04 18:05:03 debian anacron[601]: Will run job `cron.monthly' in 35 min.
nov. 04 18:05:03 debian anacron[601]: Will run job `cron.hourly' in 50 min.
nov. 04 18:05:03 debian anacron[601]: Jobs will be executed sequentially
nov. 04 18:10:02 debian anacron[601]: Job `cron.daily' started
nov. 04 18:10:02 debian anacron[1480]: Updated timestamp for job `cron.daily' to 2017-11-04
nov. 04 18:14:29 debian anacron[601]: Job `cron.daily' terminated
nov. 04 18:17:01 debian CRON[2287]: pam_unix(cron:session): session opened for user root by (uid=0)
nov. 04 18:17:01 debian CRON[2288]: (root) CMD (   test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.hourly ))
nov. 04 18:17:01 debian CRON[2287]: pam_unix(cron:session): session closed for user root
nov. 04 18:25:03 debian anacron[601]: Job `cron.weekly' started
nov. 04 18:25:03 debian anacron[2375]: Updated timestamp for job `cron.weekly' to 2017-11-04
nov. 04 18:30:21 debian anacron[601]: Job `cron.weekly' terminated (mailing output)
nov. 04 18:40:03 debian anacron[601]: Job `cron.monthly' started
nov. 04 18:40:03 debian anacron[601]: Job `cron.monthly' terminated
nov. 04 18:40:03 debian anacron[2969]: Updated timestamp for job `cron.monthly' to 2017-11-04
nov. 04 18:55:03 debian anacron[601]: Job `cron.hourly' started
nov. 04 18:55:03 debian anacron[601]: Job `cron.hourly' terminated
nov. 04 18:55:03 debian anacron[601]: Normal exit (4 jobs run)
  • L’horodatage de la fin des jobs ( il suffit de supprimer les fichiers pour que tout soit relancé au boot suivant)
root@debian:/# ls -alrt /var/spool/anacron
total 24
drwxr-xr-x 8 root root 4096 mai   25  2016 ..
drwxr-xr-x 2 root root 4096 nov.   4 18:05 .
-rw------- 1 root root    9 nov.   4 18:14 cron.daily
-rw------- 1 root root    9 nov.   4 18:30 cron.weekly
-rw------- 1 root root    9 nov.   4 18:40 cron.monthly
-rw------- 1 root root    9 nov.   4 18:55 cron.hourly
  • Et hourly sera bien relancé
nov. 04 19:02:37 debian systemd[1]: Started Run anacron jobs.
-- Subject: L'unité (unit) anacron.service a terminé son démarrage
-- L'unité (unit) anacron.service a terminé son démarrage, avec le résultat RESULT.
nov. 04 19:02:37 debian anacron[3181]: Anacron 2.3 started on 2017-11-04
nov. 04 19:02:37 debian anacron[3181]: Will run job `cron.hourly' in 50 min.
nov. 04 19:02:37 debian anacron[3181]: Jobs will be executed sequentially
root@debian:/# ls -alrt /var/spool/anacron
total 24
drwxr-xr-x 8 root root 4096 mai   25  2016 ..
drwxr-xr-x 2 root root 4096 nov.   4 18:05 .
-rw------- 1 root root    9 nov.   4 18:14 cron.daily
-rw------- 1 root root    9 nov.   4 18:30 cron.weekly
-rw------- 1 root root    9 nov.   4 18:40 cron.monthly
-rw------- 1 root root    9 nov.   4 19:52 cron.hourly
root@debian:/# who -b
         démarrage système 2017-11-04 18:04
1 J'aime

Donc comme cron est surtout utile sur une machine qui reste en ligne h 24 je n’en ai pas besoin

root@debian:/# systemctl stop cron.service
root@debian:/# systemctl disable cron.service
Synchronizing state of cron.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable cron
insserv: warning: current start runlevel(s) (empty) of script `cron' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (2 3 4 5) of script `cron' overrides LSB defaults (empty).
root@debian:/# 

Pour rester homogene, création de

root@debian:/etc/cron.hourly# cat 0anacron 
#!/bin/sh
#
# anacron's cron script
#
# This script updates anacron time stamps. It is called through run-parts
# either by anacron itself or by cron.
#
# The script is called "0anacron" to assure that it will be executed
# _before_ all other scripts.

test -x /usr/sbin/anacron || exit 0
anacron -u cron.hourly

Et voilà, je fais du cron.hourly avec anacron

systemctl status anacron.service  -l --no-pager
● anacron.service - Run anacron jobs
   Loaded: loaded (/lib/systemd/system/anacron.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2017-11-06 11:27:09 CET; 33min ago
     Docs: man:anacron
           man:anacrontab
 Main PID: 613 (anacron)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/anacron.service
           └─613 /usr/sbin/anacron -dsq

nov. 06 11:27:09 debian systemd[1]: Started Run anacron jobs.
nov. 06 11:27:09 debian anacron[613]: Anacron 2.3 started on 2017-11-06
nov. 06 11:27:10 debian anacron[613]: Will run job `cron.daily' in 5 min.
nov. 06 11:27:10 debian anacron[613]: Will run job `cron.hourly' in 50 min.
nov. 06 11:27:10 debian anacron[613]: Jobs will be executed sequentially
nov. 06 11:32:08 debian anacron[613]: Job `cron.daily' started
nov. 06 11:32:08 debian anacron[4016]: Updated timestamp for job `cron.daily' to 2017-11-06
nov. 06 11:32:09 debian cracklib[4051]: no dictionary update necessary.
nov. 06 11:34:38 debian anacron[613]: Job `cron.daily' terminated

systemctl status anacron.timer  -l --no-pager
● anacron.timer - Trigger anacron every hour
   Loaded: loaded (/lib/systemd/system/anacron.timer; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2017-11-06 11:27:09 CET; 34min ago
  Trigger: n/a

nov. 06 11:27:09 debian systemd[1]: Started Trigger anacron every hour.