-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make running cron jobs on demand more reliable #26
Comments
What do you mean by 'running separate from Apache'? Because I think any the cronjobs you're editing are those of the user which Apache is running PHP as anyway, also 'at' does its best to copy the whole environment for the command to be run in later. I've just removed the whole dependency on the 'at' command (doesn't work on OSX, my dev box), and changed the Crontab::run() to: sprintf("sh -c "%s" > /dev/null 2>&1 &", $command) Then, $process->run(); instead of $process->start();, as start() doesn't seem to move it to leave the command running in the background after returning from php (this could be the reason for any unreliable behaviour, eg when the function returns before the $process->start() has finished (should call $process->wait() for this)). $process->run() with the background command seems to work fine. If you would like, I can PR my changes. |
@micschk, thank you for your detailed note!
What I was trying to achieve is "detach" any commands being run from the Apache process triggering them, so whenever you would restart Apache your jobs would still run and not be killed pending the restart, since whenever Apache is stopped or restarted, all processes in the process group (see PGID below) receive a SIGTERM, including those launched by CronKeep. Here's a short experiment running a script called Launched from CronKeep without
Launched from CronKeep with
Admittedly the job moves under The same job launched by the cron daemon:
We can see how the job spawned by the cron service gets its very own session (see column SID). This means that when we stop cron orphaned processes will be inherited by init and keep on running:
I think what we really need is wrap the job being called by a script which calls Also, please note that we cannot afford to wait for a cron job to finish in the CronKeep UI since people can have long-running scripts that can run for hours. |
Hi micschk, |
Sometimes running cron jobs from the interface fails, and it does so in a silent way, still reporting that the job has started.
CronKeep should (better) report that a cron job failed to run and present the user with whatever information it has available (such as the command's output or the return code).
Capturing command output could be tricky to do with the current setup of running the command asynchronously (which is either scheduling it to run immediately using
at
, or viaproc_open
otherwise). CronKeep currently passes on the intricacies of invoking the process to symfony/Process, which usesproc_open
internally.We should strive to keep it running separately from Apache, if possible, which is what
at
currently does for us.A nice to have: have output coming up on the screen as the process is being executed (TBD).
The text was updated successfully, but these errors were encountered: