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

How to kill forever-monitor? #158

Open
NateZimmer opened this issue Mar 18, 2018 · 1 comment
Open

How to kill forever-monitor? #158

NateZimmer opened this issue Mar 18, 2018 · 1 comment

Comments

@NateZimmer
Copy link

I know on windows/linux I can do a targeted kill of the process but this is a bit tedious/hacky.

I was hoping killing the forever-monitor cli would stop the child processes. Other than that, I had hoped I would be able to code in a kill upon exit such as the following:

 process.on('exit', function (){
  child.stop();
});

However, not even the above worked. Anybody have an idea how I can kill forever-monitor upon the forever-monitor cli being closed? This allows more ignorant users to easily kill the system while maintaining reliability of running the underlying child script when the CLI is open.

@bennycode
Copy link
Contributor

Hey @NateZimmer, did you try the following?

const path = require('path');
const forever = require('forever-monitor');

let child;

function exit() {
  console.error('Received exit signal on main process.');
  if (child) child.stop();
  process.exit(0);
}

['SIGINT', 'SIGKILL', 'SIGTERM'].forEach(signal => process.on(signal, exit));

child = new forever.Monitor(path.join(__dirname, 'server.js'));
child.start();

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

2 participants