Score:1

Cron job on ubuntu 20 does not stop until machine restart

me flag

I have this cron job in my crontab

* * * * * while true; do curl https://example.com/Payments/cron_jobs_with_codeigniter --silent --compressed; sleep 5; done

it works but when i empty the crontab and save, and restart cron

sudo service cron restart

the cron job above is still running. When i ps aux the command is still running but each time with a different PID so i cant kill all of them since there is a new PID every 5 seconds.

How can i stop the rogue cron job without restarting the entire machine?

Score:3
cn flag

I see a couple of things I would never ever do in cron.

  1. no time (* * * * *)
  2. a while.

Please do not do this: You are dos'ing your system.

How can i stop the rogue cron job without restarting the entire machine?

Don't do it like this?

Make a script and call that script. Inside the script you insert a check to run this script only once at a time (so you do not have it running multiple times at once), and also put your while in the script.

Then start the script using a timer like "@reboot" or a time. That way your script has 1 PID you can kill but I would suggest to add something like a pid file where you read this file and have your script stop elegantly (and only have it start when the pid file says it should) (a file containing "active" or "stop" and have the script continue or stop itself; where cron restarts it and checks the file).

The same effect can be achieved by not using a script but using a systemd unit where you do not need cron at all. That way you can use the start/stop/restart options of systemd to manipulate your unit.

Score:1
me flag

I wrote this supervisor script to handle the scheduled runs

I began by creating the file

sudo nano /etc/supervisor/conf.d/cron_jobs_with_codeigniter.conf
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl
supervisor > start cron_jobs_with_codeigniter
supervisor > status
supervisor > quit

then wrote this

[program:cron_jobs_with_codeigniter]
process_name=%(program_name)s_%(process_num)02d
numprocs=2
command= curl https://example.com/Payments/cron_jobs_with_codeigniter
autostart=true
autorestart=true
startsecs=0
startretries=3
exitcodes=0,2
stopsignal=TERM
stopwaitsecs=5
stopasgroup=true
killasgroup=true
stderr_logfile=/var/log/cron_jobs_with_codeigniter.err.log
stdout_logfile=/var/log/cron_jobs_with_codeigniter.out.log
I sit in a Tesla and translated this thread with Ai:

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.