Skip to content
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

forever stop does not stop child processes #621

Closed
tjwebb opened this issue Oct 28, 2014 · 17 comments
Closed

forever stop does not stop child processes #621

tjwebb opened this issue Oct 28, 2014 · 17 comments

Comments

@tjwebb
Copy link

tjwebb commented Oct 28, 2014

If I use something like sudo -u in my forever script, the sudo process is stopped but the actual process that I care about is still running after I stop it. Is there some way to kill the entire process group?

@indexzero
Copy link
Member

This is a duplicate of #544. It's because you are running as a different user and it can't find the bookkeeping files.

@tjwebb
Copy link
Author

tjwebb commented Nov 2, 2014

forever list works fine. And it does kill the parent process, but not the
child process.
On Oct 30, 2014 4:35 AM, "Charlie Robbins" [email protected] wrote:

Closed #621 #621.


Reply to this email directly or view it on GitHub
#621 (comment).

@indexzero
Copy link
Member

Oh, in that case I believe you want the --killTree option.

@tjwebb
Copy link
Author

tjwebb commented Nov 3, 2014

killTree has no effect. It's already set to true in my config

@indexzero
Copy link
Member

What operating system are you on? You might also consider what --killSignal you are sending.

@tjwebb
Copy link
Author

tjwebb commented Nov 3, 2014

Ubuntu 14.04.

Everything stops correctly if I manually pgrep for the processes and kill -9 them. But forever only kills the forever-monitor and sudo processes. The actual node processes I want to kill are no longer in the forever list, but are still running.

@indexzero
Copy link
Member

Hmm that is strange since forever-monitor is by default sending the SIGKILL signal which is the same as kill -9

http://askubuntu.com/a/184079

@tjwebb
Copy link
Author

tjwebb commented Nov 3, 2014

Yea, it sends SIGKILL only to the forever-monitor and sudo -u
processes. No signal is sent to the node process at all, despite killTree
being set to true.

On Mon, Nov 3, 2014 at 2:51 PM, Charlie Robbins [email protected]
wrote:

Hmm that is strange since forever-monitor is by default sending the
SIGKILL signal which is the same as kill -9

http://askubuntu.com/a/184079


Reply to this email directly or view it on GitHub
#621 (comment).

@indexzero
Copy link
Member

So all of the killTree functionality is done via the ps-tree module which is actually super brittle and a place I would love to help improve.

It just spawns:

ps -A -o ppid,pid

And then parses the output.

@indexzero
Copy link
Member

For reference: https://github.com/indexzero/ps-tree/blob/master/index.js#L15

... do you have some time to run that command exactly and see what's going on?

@tjwebb
Copy link
Author

tjwebb commented Nov 3, 2014

Ok. To solve this, I wrote a pgrep module that finds the processes that forever is not correctly finding: https://github.com/tjwebb/node-pgrep.

Maybe this can be integrated into forever at some point.

@indexzero
Copy link
Member

is pgrep guaranteed to be on all systems?

@tjwebb
Copy link
Author

tjwebb commented Nov 3, 2014

no idea

@indexzero
Copy link
Member

Any interest in finding out to help fix this issue? :)

@tjwebb
Copy link
Author

tjwebb commented Nov 3, 2014

Yea, I'll do some research later. Thanks for your help in pointing me in the right direction.

@indexzero
Copy link
Member

Thank you for bearing with me. I'm going to leave this closed, but open a corresponding issue on forever-monitor.

@sugir93
Copy link

sugir93 commented Jan 4, 2018

function exitHandler(options, err) {
console.log(err.stack);
child_process.stop();
process.exit();
}

//do something when app is closing
process.on('exit', exitHandler.bind(null,{cleanup:true}));

//catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {exit:true}));

// catches "kill pid" (for example: nodemon restart)
process.on('SIGUSR1', exitHandler.bind(null, {exit:true}));
process.on('SIGUSR2', exitHandler.bind(null, {exit:true}));

//catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {exit:true}));

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

No branches or pull requests

3 participants