heroku和sails应用程序|崩溃和超时 [英] heroku and sails app | crashes and timeouts

查看:260
本文介绍了heroku和sails应用程序|崩溃和超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的sails应用程序在本地运行。当我部署到Heroku时,我无法从应用程序获得响应,然后最终得到应用程序错误。我有时会收到没有收到任何数据。



heroku日志

  2015-08-30T22:06:50.949475 + 00:00 heroku [api]:发布v22由我创建

2015-08-30T22:08:57.324207 + 00: 00 heroku [router]:at = error code = H20 desc =App boo
t timeoutmethod = GET path =/host = www.ninjalist.io request_id = 8e21f6eb-1a59-4e
31 -9c40-00aab002d0f1 fwd =118.61.238.166dyno = connect = service = status = 503 bytes =

2015-08-30T22:08:52.058851 + 00:00 heroku [web.1]:状态从开始变为下降

2015-08-30T22:11:55.735176 + 00:00 heroku [router]:at = error code = H10 desc =App cra
shedmethod = GET path =/host = ninjalist.herokuapp.com request_id = 314047d1-97d8-
40ea-8596-4b21978eb581 fwd =108.61.228.166dyno = connect = service = status = 503 b



heroku日志 - 来源应用


  2015-08-30T21:40:42.149449 + 00:00 app [web.1]:> firstApp@0.0.1 start / app 
2015-08-30T21:40:42.149452 + 00:00 app [web.1]:> sails lift --prod
2015-08-30T21:40:42.149453 + 00:00 app [web.1]:
2015-08-30T21:40:42.149430 + 00:00 app [web。 1]:
2015-08-30T21:40:42.873435 + 00:00 app [web.1]:←[90mStarting app ...←[39m
2015-08-30T21:40:42.871270 +00:00 app [web.1]:
2015-08-30T21:40:42.873742 + 00:00 app [web.1]:
2015-08-30T21:40:44.441658 + 00 :00 app [web.1]:Warning:connect.session()MemorySt
不是
2015-08-30T21:40:44.441664 + 00:00 app [web.1]:专为生产环境
nt,因为它会泄漏
2015-08-30T21:40:44.441666 + 00:00 app [web.1]:内存,并且不会按照
ingle处理。
2015-08-30T21:41:04.326177 + 00:00 app [web.1]:错误:钩子`grunt`花费t
oo来加载。
2015-08-30T21:41:04.326187 + 00:00 app [web.1]:在Timer.listOnTimeout(定时器。
js:119:15)
2015-08-30T21 :41:04.326183 + 00:00 app [web.1]:确保它触发`ini
tialize()`回调,否则将sails.config.grunt._hookTimeout设置为更高的值。 $ b lue(目前为20000)
2015-08-30T21:41:04.326185 + 00:00 app [web.1]:在tooLong [as _onTimeout](/ ap
p / node_modules / sails / lib /app/private/loadHooks.js:92:21)
2015-08-30T21:41:04.587989 + 00:00 app [web.1]:
2015-08-30T21:41:04.641592 +00:00应用[web.1]:npm ERR! argv/app/.heroku/node/bi
n / node/app/.heroku/node/bin/npmstart
2015-08-30T21:41:04.641839 + 00: 00 app [web.1]:npm ERR! node v0.12.7
2015-08-30T21:41:04.668957 + 00:00 app [web.1]:npm ERR! npm v2.11.3
2015-08-30T21:41:04.669159 + 00:00 app [web.1]:npm ERR!代码ELIFECYCLE
2015-08-30T21:41:04.669368 + 00:00 app [web.1]:npm ERR! firstApp@0.0.1 start:`sai
ls lift --prod`
2015-08-30T21:41:04.669504 + 00:00 app [web.1]:npm ERR!退出状态1
2015-08-30T21:41:04.669672 + 00:00 app [web.1]:npm ERR!
2015-08-30T21:41:04.669827 + 00:00 app [web.1]:npm ERR!在第一个App@0.0
.1开始脚本'sails lift --prod'失败。
2015-08-30T21:41:04.670024 + 00:00 app [web.1]:npm ERR!这很可能是firstApp软件包
2015-08-30T21:41:04.670133 + 00:00 app [web.1]:npm ERR!而不是npm本身。
2015-08-30T21:41:04.670267 + 00:00 app [web.1]:npm ERR!告诉作者这个
在你的系统上失败:
2015-08-30T21:41:04.670427 + 00:00 app [web.1]:npm ERR! sails lift --prod
2015-08-30T21:41:04.675558 + 00:00 app [web.1]:npm ERR!你可以通过
获得他们的信息:
2015-08-30T21:41:04.676317 + 00:00 app [web.1]:npm ERR! npm owner ls firstApp
2015-08-30T21:41:04.697584 + 00:00 app [web.1]:
2015-08-30T21:41:04.676320 + 00:00 app [web.1 ]:npm ERR!上面可能会有额外的
日志输出。
2015-08-30T21:41:04.701882 + 00:00 app [web.1]:npm ERR! /app/npm-debug.log
2015-08-30T21:41:04.640986 + 00:00 app [web.1]:npm ERR! Linux 3.13.0-61-

Procfile

  web:npm start 

package.json / scripts

 scripts:{
debug :node debug app.js,
start:sails lift --prod
}

config / env / production

  module.exports = {

模型:{
连接:'mongoDbProd'
},

端口:80,

log:{
等级:沉默
}

};

任何方向感谢!

解决方案

您也可以使用Heroku的专用构建包,在部署时运行Grunt任务,然后在生产环境中关闭Sails中的Grunt。这需要更多的工作,但它可能是必要的,因为Heroku有它自己的超时时间,可能会被Grunt绊倒花费太长的时间来关闭你的资产。



我们已经有了成功与 heroku-buildpack-nodejs-grunt 。您可以按照说明将其安装到您的Heroku应用程序中,然后将任务定义复制到 tasks / register / prod.js 中以包含 heroku:生产任务,例如:

  module.exports = function(grunt){

grunt.registerTask('prod',[
'compileAssets',
'concat',
'uglify',
'cssmin',
'sails -linker:prodJs',
'sails-linker:prodStyles',
'sails-linker:devTpl',
'sails-linker:prodJsJade',
'sails-linker :prodStylesJade',
'sails-linker:devTplJade'
]);

grunt.registerTask('heroku:production',[
'compileAssets',
'concat',
'uglify',
'cssmin' ,
'sails-linker:prodJs',
'sails-linker:prodStyles',
'sails-linker:devTpl',
'sails-linker:prodJsJade',
'sails-linker:prodStylesJade',
'sails-linker:devTplJade'
]);

};

然后在你的 app.js 文件中,替换

  sails.lift(rc('sails')); 

附带:

  var config = rc('sails'); 
if(process.env.NODE_ENV ==='production'){
config.hooks = config.hooks || {};
config.hooks.grunt = false;
}
//启动服务器
sails.lift(config);


I have a very basic sails app up and running locally. When I deploy to Heroku, I cannot get a response from the app and then eventually get "Application Error". I sometimes receive "No data received".

heroku logs

2015-08-30T22:06:50.949475+00:00 heroku[api]: Release v22 created by me

2015-08-30T22:08:57.324207+00:00 heroku[router]: at=error code=H20 desc="App boo
t timeout" method=GET path="/" host=www.ninjalist.io request_id=8e21f6eb-1a59-4e
31-9c40-00aab002d0f1 fwd="118.61.238.166" dyno= connect= service= status=503 bytes=

2015-08-30T22:08:52.058851+00:00 heroku[web.1]: State changed from starting to down

2015-08-30T22:11:55.735176+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/" host=ninjalist.herokuapp.com request_id=314047d1-97d8-
40ea-8596-4b21978eb581 fwd="108.61.228.166" dyno= connect= service= status=503 b

heroku logs --source app

2015-08-30T21:40:42.149449+00:00 app[web.1]: > firstApp@0.0.1 start /app
2015-08-30T21:40:42.149452+00:00 app[web.1]: > sails lift --prod
2015-08-30T21:40:42.149453+00:00 app[web.1]:
2015-08-30T21:40:42.149430+00:00 app[web.1]:
2015-08-30T21:40:42.873435+00:00 app[web.1]: ←[90mStarting app...←[39m
2015-08-30T21:40:42.871270+00:00 app[web.1]:
2015-08-30T21:40:42.873742+00:00 app[web.1]:
2015-08-30T21:40:44.441658+00:00 app[web.1]: Warning: connect.session() MemorySt
ore is not
2015-08-30T21:40:44.441664+00:00 app[web.1]: designed for a production environme
nt, as it will leak
2015-08-30T21:40:44.441666+00:00 app[web.1]: memory, and will not scale past a s
ingle process.
2015-08-30T21:41:04.326177+00:00 app[web.1]: Error: The hook `grunt` is taking t
oo long to load.
2015-08-30T21:41:04.326187+00:00 app[web.1]:     at Timer.listOnTimeout (timers.
js:119:15)
2015-08-30T21:41:04.326183+00:00 app[web.1]: Make sure it is triggering its `ini
tialize()` callback, or else set `sails.config.grunt._hookTimeout to a higher va
lue (currently 20000)
2015-08-30T21:41:04.326185+00:00 app[web.1]:     at tooLong [as _onTimeout] (/ap
p/node_modules/sails/lib/app/private/loadHooks.js:92:21)
2015-08-30T21:41:04.587989+00:00 app[web.1]:
2015-08-30T21:41:04.641592+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bi
n/node" "/app/.heroku/node/bin/npm" "start"
2015-08-30T21:41:04.641839+00:00 app[web.1]: npm ERR! node v0.12.7
2015-08-30T21:41:04.668957+00:00 app[web.1]: npm ERR! npm  v2.11.3
2015-08-30T21:41:04.669159+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2015-08-30T21:41:04.669368+00:00 app[web.1]: npm ERR! firstApp@0.0.1 start: `sai
ls lift --prod`
2015-08-30T21:41:04.669504+00:00 app[web.1]: npm ERR! Exit status 1
2015-08-30T21:41:04.669672+00:00 app[web.1]: npm ERR!
2015-08-30T21:41:04.669827+00:00 app[web.1]: npm ERR! Failed at the firstApp@0.0
.1 start script 'sails lift --prod'.
2015-08-30T21:41:04.670024+00:00 app[web.1]: npm ERR! This is most likely a prob
lem with the firstApp package,
2015-08-30T21:41:04.670133+00:00 app[web.1]: npm ERR! not with npm itself.
2015-08-30T21:41:04.670267+00:00 app[web.1]: npm ERR! Tell the author that this
fails on your system:
2015-08-30T21:41:04.670427+00:00 app[web.1]: npm ERR!     sails lift --prod
2015-08-30T21:41:04.675558+00:00 app[web.1]: npm ERR! You can get their info via
:
2015-08-30T21:41:04.676317+00:00 app[web.1]: npm ERR!     npm owner ls firstApp
2015-08-30T21:41:04.697584+00:00 app[web.1]:
2015-08-30T21:41:04.676320+00:00 app[web.1]: npm ERR! There is likely additional
 logging output above.
2015-08-30T21:41:04.701882+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2015-08-30T21:41:04.640986+00:00 app[web.1]: npm ERR! Linux 3.13.0-61-

Procfile:

web: npm start

package.json / scripts:

  "scripts": {
    "debug": "node debug app.js",
    "start": "sails lift --prod"
  }

config/env/production:

module.exports = {

  models: {
    connection: 'mongoDbProd'
  },

  port: 80,

  log: {
     level: "silent"
  }

};

Any direction is appreciated!

解决方案

You can also use a specialized buildpack for Heroku that runs the Grunt tasks on deployment, and then turn off Grunt in Sails for the production environment. It's a bit more work, but it can become necessary because Heroku has its own timeout which can be tripped by Grunt taking too long to crunch your assets.

We've had success with heroku-buildpack-nodejs-grunt. You can follow the instructions to install it on your Heroku app, then copy the task definition in your tasks/register/prod.js to include heroku:production task, e.g.:

module.exports = function (grunt) {

  grunt.registerTask('prod', [
    'compileAssets',
    'concat',
    'uglify',
    'cssmin',
    'sails-linker:prodJs',
    'sails-linker:prodStyles',
    'sails-linker:devTpl',
    'sails-linker:prodJsJade',
    'sails-linker:prodStylesJade',
    'sails-linker:devTplJade'
  ]);

  grunt.registerTask('heroku:production', [
    'compileAssets',
    'concat',
    'uglify',
    'cssmin',
    'sails-linker:prodJs',
    'sails-linker:prodStyles',
    'sails-linker:devTpl',
    'sails-linker:prodJsJade',
    'sails-linker:prodStylesJade',
    'sails-linker:devTplJade'
  ]);

};

Then finally in your app.js file, replace

sails.lift(rc('sails'));

with:

var config = rc('sails');
if (process.env.NODE_ENV === 'production') {
  config.hooks = config.hooks || {};
  config.hooks.grunt = false;
}
// Start server
sails.lift(config);

这篇关于heroku和sails应用程序|崩溃和超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆