6

I've switched from cron to systemd-cron with my Debian unstable system, but now the daily "cron job" often fails, because it runs mixmaster which fetches its database from the Internet and if the cron-daily.timer gets triggered before the network is up, after wake-up from suspend to RAM, mixmaster can't reach the server.

Apr 24 11:02:23 run-parts[13608]: /usr/bin/mixmaster-update: Get failed for http://www.noreply.org/echolot/pgp-all.asc (500 Can't connect to www.noreply.org:80)
Apr 24 11:02:23 run-parts[13608]: Downloading of mlist and/or mixring failed (do you need a proxy?). Aborting.
Apr 24 11:02:23 su[13809]: pam_unix(su:session): session closed for user mixmaster
Apr 24 11:02:23 run-parts[13608]: run-parts: /etc/cron.daily/mixmaster exited with return code 22

Is it possible to delay the timer until the network is up and running?

2
  • So the situation is you open your laptop lid, and then the timer triggered service immediately runs "quickly before the network has come up yet"?
    – rogerdpack
    Jul 9, 2019 at 16:48
  • @rogerdpack: Yes, it runs before the network (WLAN) is ready. Sometimes the WLAN connect takes a few minutes.
    – jo-so
    Jul 10, 2019 at 19:53

3 Answers 3

2

Use systemd timers instead of cron.

Then in your systemd-unit, you can specify After=network-online.target and Wants=network-online.target.

2
  • 2
    This doesn't help, because the target becomes active after boot, but remains untouched when the network goes down due to suspend to RAM e.g.
    – jo-so
    Apr 25, 2017 at 17:39
  • If all else fails, you can add a "sleep" statement to the script you run, to have it wait for a period before attempting to connect, like ExecStartPre=/bin/sleep 60 Apr 25, 2017 at 18:25
1

It might be worth using systemd's timers rather than cron. You should then be able to specify in the unit what it depends on.

https://wiki.archlinux.org/index.php/Systemd#Handling_dependencies

1
0

In my setup the cron job is run every minute, but quits if there is no internet connection, by a connectivity test such as

nc -zw3 github.com 22 || exit 0

When there finally is an internet connection, then, once a day, the anacron jobs are run.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .