{"action":"created","issue":{"url":"https://api.github.com/repos/foreverjs/forever/issues/749","repository_url":"https://api.github.com/repos/foreverjs/forever","labels_url":"https://api.github.com/repos/foreverjs/forever/issues/749/labels{/name}","comments_url":"https://api.github.com/repos/foreverjs/forever/issues/749/comments","events_url":"https://api.github.com/repos/foreverjs/forever/issues/749/events","html_url":"https://github.com/foreverjs/forever/issues/749","id":100132793,"number":749,"title":"Forever stop, does not kill forever-monitor child","user":{"login":"xpiwo","id":10696532,"avatar_url":"https://avatars.githubusercontent.com/u/10696532?v=3","gravatar_id":"","url":"https://api.github.com/users/xpiwo","html_url":"https://github.com/xpiwo","followers_url":"https://api.github.com/users/xpiwo/followers","following_url":"https://api.github.com/users/xpiwo/following{/other_user}","gists_url":"https://api.github.com/users/xpiwo/gists{/gist_id}","starred_url":"https://api.github.com/users/xpiwo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xpiwo/subscriptions","organizations_url":"https://api.github.com/users/xpiwo/orgs","repos_url":"https://api.github.com/users/xpiwo/repos","events_url":"https://api.github.com/users/xpiwo/events{/privacy}","received_events_url":"https://api.github.com/users/xpiwo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-10T18:08:16Z","updated_at":"2016-03-05T03:40:34Z","closed_at":null,"body":"Working in forever@0.10.8, does not work in latest forever.\r\n\r\nserver.js:\r\n```\r\nvar http = require('http');\r\nhttp.createServer(function (req, res) {\r\nres.end('bye')\r\n}).listen(1337);\r\n```\r\n\r\nmonitor.js:\r\n```\r\nvar forever = require('forever-monitor');\r\n\r\nvar child = new (forever.Monitor)('server.js', {\r\n    max: 3,\r\n    killTree: true,\r\n    silent: true,\r\n    args: []\r\n});\r\n\r\nchild.on('exit', function () {\r\n    console.log('your-filename.js has exited after 3 restarts');\r\n});\r\n\r\nchild.start();\r\n```\r\n\r\nrunning:\r\nforever start monitor.js\r\nforever stop monitor.js\r\n\r\nserver.js still keeps running in background"},"comment":{"url":"https://api.github.com/repos/foreverjs/forever/issues/comments/192562395","html_url":"https://github.com/foreverjs/forever/issues/749#issuecomment-192562395","issue_url":"https://api.github.com/repos/foreverjs/forever/issues/749","id":192562395,"user":{"login":"kengz","id":8209263,"avatar_url":"https://avatars.githubusercontent.com/u/8209263?v=3","gravatar_id":"","url":"https://api.github.com/users/kengz","html_url":"https://github.com/kengz","followers_url":"https://api.github.com/users/kengz/followers","following_url":"https://api.github.com/users/kengz/following{/other_user}","gists_url":"https://api.github.com/users/kengz/gists{/gist_id}","starred_url":"https://api.github.com/users/kengz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kengz/subscriptions","organizations_url":"https://api.github.com/users/kengz/orgs","repos_url":"https://api.github.com/users/kengz/repos","events_url":"https://api.github.com/users/kengz/events{/privacy}","received_events_url":"https://api.github.com/users/kengz/received_events","type":"User","site_admin":false},"created_at":"2016-03-05T03:40:34Z","updated_at":"2016-03-05T03:40:34Z","body":"`SIGTERM` is the recommended signal to use as suggested by nodejs [docs](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)\r\nPutting these out here: appending these at the bottom of the script will allow for cleaner exist, and ensure that all children gets terminated when the parent exits:\r\n```js\r\nprocess.on('exit', function() {\r\n  children.forEach(function(child) {\r\n    child.kill();\r\n  });\r\n  console.log('Exit: killed children')\r\n});\r\n\r\nvar cleanExit = function() { process.exit() };\r\nprocess.on('SIGINT', cleanExit); // catch ctrl-c\r\nprocess.on('SIGTERM', cleanExit); // catch kill\r\n\r\n```"}}