Skip to content

pm2 with cron_restart restarts process while the process is still running #2395

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

Closed
rachel-benh opened this issue Sep 21, 2016 · 12 comments
Closed

Comments

@rachel-benh
Copy link

If reporting a bug, please use the following template.

Expected behaviour

I need to prevent restarting script if the former didn't terminate

Actual behaviour

The script restarts

Steps to reproduce

...

Software versions used

OS         :
node.js    : 4.4.0
PM2        : latest

PM2 Log output

Use the command: tail --lines 50 ~/.pm2/pm2.log

PM2 App [temp] with id [1] and pid [43887], exited with code [0] via signal [SIGINT]
PM2 Starting execution sequence in -fork mode- for app name:temp id:1
PM2 App name:temp id:1 online
PM2 Starting execution sequence in -fork

I tried listening to process.on('SIGINT', function() {..}
to prevent exit if the script wan't done but it doesn't seem to enter the function.
Same for process.on('message', function(msg)

Thanks!

@Unitech
Copy link
Owner

Unitech commented Sep 21, 2016

Could you please double check that it does not enters in the SIGINT function.

Something else, increase kill_timeout

@rachel-benh
Copy link
Author

rachel-benh commented Sep 21, 2016

Hi,
thanks.
I created

 process.on('SIGINT', function() {
    process.stdout.write('received SIGINT');
...
}

And there weren't any log prints.
I already tried setting "kill_timeout": 3000

@rachel-benh
Copy link
Author

we tried to listen to exit and that worked...
Is there a configuration to prevent pm2 from stopping running scripts?

@Yontih
Copy link

Yontih commented Sep 22, 2016

+1
Same for me, cron restarts the process while the process is still running.

@vmarchaud
Copy link
Contributor

vmarchaud commented Sep 22, 2016

Cause the cron is running process.exit(0) from inside the process, the process itself do not receive the SIGINT.
Feel free to make a PR to fix that.

@Yontih
Copy link

Yontih commented Sep 22, 2016

@vmarchaud it is looks like the cron is running process.exit with status code 0 not 1 ProcessContainerFork.js line 25

@vmarchaud
Copy link
Contributor

vmarchaud commented Sep 22, 2016

@Yontih Mybad i corrected my answer, but it doesnt change anything.

@Unitech
Copy link
Owner

Unitech commented Sep 24, 2016

Thanks for the PR @Yontih, just made some change to harden the cron workflow (restart instead of raw kill) + some tests

You can try it:

$ npm install Unitech/pm2#development -g
$ pm2 update

@Yontih
Copy link

Yontih commented Sep 24, 2016

@Unitech
What if god.js (pm2) will manage the crons (start/restart child_process) instead of every child_process to run is own cron?
For example: I have a script that I want to run everyday at 00:00, I wont be able to kill my script process when it finish is work, because the cron will die as well and my script will never run again.

@Unitech
Copy link
Owner

Unitech commented Sep 29, 2016

Landed in latest PM2 stable

$ npm install pm2@latest -g

@Unitech Unitech closed this as completed Sep 29, 2016
@Unitech
Copy link
Owner

Unitech commented Sep 29, 2016

@Yontih sounds interesting, PR welcome

@zackees
Copy link

zackees commented May 19, 2024

Also hitting this with using cron. All python processes spawned with ProcessPoolExecutor remain alive after job completion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants