Node.js停止与“发送SIGTERM给孩子”没有理由

这个问题与https://www.openshift.com/forums/openshift/nodejs-process-stopping-for-no-reason上发布的相同。 不幸的是,它仍然没有答案。

今天,我的Node.js应用程序停止了几次DEBUG: Sending SIGTERM to child...在日志文件上。 没有更多,不能less。 我的应用程序是一个非常简单的单页面应用程序,具有单个AJAX端点,每天提供1k-2k的综合浏览量。 它已经运行好几天没有任何问题。

我使用这些模块:

  • performance
  • 身体parsing器
  • 请求
  • cheerio

– 更新:

  1. 我正在使用一个小齿轮。 512MB内存,1GB存储空间

  2. 日志文件摘录( ~/app-root/logs/nodejs.log

     Thu Jul 17 2014 09:12:52 GMT-0400 (EDT) <redacted app log message> Thu Jul 17 2014 09:13:09 GMT-0400 (EDT) <redacted app log message> Thu Jul 17 2014 09:14:33 GMT-0400 (EDT) <redacted app log message> DEBUG: Sending SIGTERM to child... #### below are the log entries after issuing "ctl_app restart" DEBUG: Running node-supervisor with DEBUG: program 'server.js' DEBUG: --watch '/var/lib/openshift/redacted/app-root/data/.nodewatch' DEBUG: --ignore 'undefined' DEBUG: --extensions 'node|js|coffee' DEBUG: --exec 'node' DEBUG: Starting child process with 'node server.js' 
  3. 来自oo-cgroup-read统计信息,正如@niharvey所build议的那样。 有点太长,所以我把它放在http://pastebin.com/c31gCHGZ 。 显然我使用了太多的内存: memory.failcnt 40583 。 我想Node.js是自动(?)重新启动内存过度使用事件,但在这种情况下,它不是。 我不得不手动重启。

  4. 我忘记了我已经安装了一个空闲的MySQL盒式磁盘,现在已经被删除

– 更新#2

该应用程序刚刚崩溃了。 memory.failcnt值保持不变(完整统计在http://pastebin.com/LqbBVpV9 ),所以这不是内存问题(?)。 但是日志文件有差异。 该应用程序似乎重新启动,但失败。 在ctl_app restart它的工作原理如图所示。

  Thu Jul 17 2014 22:14:46 GMT-0400 (EDT) <redacted app log message> Thu Jul 17 2014 22:15:03 GMT-0400 (EDT) <redacted app log message> DEBUG: Sending SIGTERM to child... ==> app-root/logs/nodejs.log-20140714113010 <== at Function.Module.runMain (module.js:497:10) DEBUG: Program node server.js exited with code 8 DEBUG: Starting child process with 'node server.js' module.js:340 throw err; ^ Error: Cannot find module 'body-parser' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) 

要在本地机器上模拟此问题,请在一个terminal窗口中使用主pipe器运行服务器:

 supervisor server.js 

然后从另一个terminal使用kill命令

 kill process_id# 

不带参数的kill命令向应用程序发送SIGTERM消息。 如果主pipe收到一个SIGTERM,它将立即停止。

来自OpenShift提供的示例应用程序的示例代码监听12个不同的unix信号并退出。 可能是因为应用程序没有收听意图重启它的信号,OpenShift上的某个人正在手动终止进程。 我将这个代码添加到我的应用程序,看看这个行为是否更稳定。

 function terminator(sig){ if (typeof sig === "string") { console.log('%s: Received %s - terminating sample app ...', Date(Date.now()), sig); process.exit(1); } console.log('%s: Node server stopped.', Date(Date.now()) ); }; process.on('exit', function() { terminator(); }); ['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM' ].forEach(function(element, index, array) { process.on(element, function() { terminator(element); }); }); 

通常这是因为你的应用程序闲置。 当你进入应用程序,你应该看到像这样的东西:

  *** This gear has been temporarily unidled. To keep it active, access *** your app @ http://abc.rhcloud.com/ 

您可以尝试使用预定的ping来保持应用程序的活着。

我有同样的问题。 我删除了装备,并创build了一个新的。 新的已经运行了几天,似乎没有问题。

[更新]几天后,这个问题出现在我的新装备上。