Score:1

How can I make my cronjob friendly to reboot and other interruptions?

pr flag

I have as part of my cronjob a variable random delay. This has good reasons to exist, it's to distribute the load of the automated process from spiking on various minute or hour boundaries.

I suspect (but am not certain) that sometimes when I reboot the machine, systemd hangs uncomfortably for a variable length of time "waiting for anacron jobs". This does not happen often enough to be worth deep-diving for source of truth, but given that I only ever set up one cronjob on my computers it seems a likely culprit.

I'm curious to know if there is an industry standard simple technique that can be used within a script that is configured as a cron job to make it interruptible. The idea here is that if I command my system to reboot, under no circumstance do I need this job (which has a variable random length sleep before it does its actual work) to complete and I want it to be interrupted and nuked from orbit when the system goes for reboot. Is there some way to do this? Will cron or the system send a signal to the configured job script? Must I resort to a custom incantation to check for jobs that are running first, terminate them and stop them from restarting, and then issue the reboot?

jp flag
Is this [bug report](https://bugs.launchpad.net/ubuntu/+source/anacron/+bug/1906617) relevant
Score:1
cn flag

Instead of using cron, you could create a systemd service

When creating the service you can set the KillMode and KillSignal options in the service options.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.