2014-04-25 87 views
3

我正在开发heroku上的node.js应用程序。现在它运行在单一(免费)动态。Heroku - 一直崩溃

由于某种原因突然我的应用程序崩溃,现在它一直崩溃(我添加NewRelic和Librato插件后观察它 - 应用程序是添加这些插件时重新启动) - 应用程序之后第一次崩溃插件被添加。所以我删除了两个插件,但问题仍然存在。我想检查什么是错,我的评论我的应用程序代码,并用简单的例子,取而代之的是从网站:

index.js

var http = require('http'); 
http.createServer(function (req, res) { 
    res.writeHead(200, {'Content-Type': 'text/plain'}); 
    res.end('Hello World\n'); 
}).listen(process.env.PORT); 
console.log('Server running at http://127.0.0.1:1337/'); 

Procfile

web: node index.js 

引擎在packages.json(由heroku安装的节点为0.10.26)

"engines": { 
    "node": "0.10.x" 
}, 

此代码适用于我的电脑(与工头一起测试)。 当我尝试将它部署到Heroku的应用程序崩溃 - 这里是日志:

2014-04-25T09:43:42+00:00 heroku[slug-compiler]: Slug compilation started 
2014-04-25T09:43:47.850609+00:00 heroku[api]: Release v30 created by xxx 
2014-04-25T09:43:47.850538+00:00 heroku[api]: Deploy 562babb by xxx 
2014-04-25T09:43:47+00:00 heroku[slug-compiler]: Slug compilation finished 
2014-04-25T09:43:48.588089+00:00 heroku[web.1]: State changed from crashed to starting 
2014-04-25T09:43:55.655057+00:00 heroku[web.1]: Starting process with command `node index.js` 
2014-04-25T09:43:57.931274+00:00 heroku[web.1]: Process exited with status 8 
2014-04-25T09:43:57.945393+00:00 heroku[web.1]: State changed from starting to crashed 

当我尝试heroku restart

2014-04-25T09:44:43.071357+00:00 heroku[web.1]: State changed from crashed to starting 
2014-04-25T09:44:51.834860+00:00 heroku[web.1]: Starting process with command `node index.js` 
2014-04-25T09:44:54.250631+00:00 heroku[web.1]: State changed from starting to crashed 
2014-04-25T09:44:54.235545+00:00 heroku[web.1]: Process exited with status 8 

这让我疯了 - 我部署了许多节点应用到Heroku的这正在生产中运行,并从来没有这样的问题 - 怎么回事?


当我改变节点引擎版本0.10.20(我用的这款V localy),那么应用程序启动并工作,但是当我做heroku restart再次崩溃...

State changed from up to starting 
2014-04-25T10:10:12.990317+00:00 heroku[web.1]: Stopping all processes with SIGTERM 
2014-04-25T10:10:15.145758+00:00 heroku[web.1]: Process exited with status 143 
2014-04-25T10:10:16.151380+00:00 heroku[web.1]: Starting process with command `node index.js` 
2014-04-25T10:10:18.905637+00:00 heroku[web.1]: Process exited with status 8 
2014-04-25T10:10:18.929730+00:00 heroku[web.1]: State changed from starting to crashed 

在第二次重新启动应用程序后up并再次运行,并在第三次重新启动后再次崩溃(它总是崩溃/退出状态8)。

回答

1

问题可能在Heroku本身。有一个小时前创建的事件报告,但它仍然不清楚导致问题的原因: https://status.heroku.com/incidents/614

同时,您可能希望通过HerokuDashboard回滚到应用程序的前一个工作版本。

+0

试图回滚和问题仍然存在:(这就是疯狂 - 它似乎是heroku问题 - > +1指出链接到heroku事件 – user606521

0

问题是你试图从一个无效端口开始。 Heroku没有在环境中设置你的PORT变量(如果你运行heroku config,你可以看到这个)。您的PORT变量必须在Procfile中明确使用。

你应该做这样的事情在你的Procfile:

web: node index.js $PORT 

然后修改index.js代码说:

var http = require('http'); 
http.createServer(function (req, res) { 
    res.writeHead(200, {'Content-Type': 'text/plain'}); 
    res.end('Hello World\n'); 
}).listen(process.argv[2]); 
console.log('Server running at http://127.0.0.1:' + process.argv[2]); 
+0

这是不正确的 - 事实上,heroku确实设置了'process.env。端口“ - 这是heroku问题,现在已经解决,一切正常。 – user606521

+0

$ PORT解决了我的问题,非常感谢 – TimCodes