简体   繁体   English

是否有必要在OpenShift上使用Forever.js?

[英]Is it necessary to use Forever.js on OpenShift?

I've deployed my first Node.js app on OpenShift's free tier, and it works great. 我在OpenShift的免费套餐上部署了我的第一个Node.js应用程序,它运行良好。

Will OpenShift automatically restart my Node app when it crashes, or do I have to set up Forever.js? OpenShift会在崩溃时自动重启我的Node应用程序,还是我必须设置Forever.js? I tried setting it up, and it would not work. 我尝试设置它,它不会工作。 After running node_modules/forever/bin/forever start app.js (working dir was app-root/repo , with local copy of forever ) I got this output: 运行node_modules/forever/bin/forever start app.js (工作目录是app-root/repoforever本地副本)我得到了这个输出:

warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: app.js

fs.js:240
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory '/var/lib/openshift/5397416f5004466c0b000080/.forever/VQMF.log'
    at Object.openSync (fs.js:240:18)
    at Object.startDaemon (/var/lib/openshift/5397416f5004466c0b000080/app-root/runtime/repo/node_modules/forever/lib/forever.js:406:14)
    at /var/lib/openshift/5397416f5004466c0b000080/app-root/runtime/repo/node_modules/forever/lib/forever/cli.js:258:13
    at /var/lib/openshift/5397416f5004466c0b000080/app-root/runtime/repo/node_modules/forever/lib/forever/cli.js:145:5
    at Object.oncomplete (/var/lib/openshift/5397416f5004466c0b000080/app-root/runtime/repo/node_modules/forever/lib/forever.js:358:11)

So, does OpenShift manage my app's health for me, or will I need to get Forever working? 那么,OpenShift是否为我管理我的应用程序的运行状况,或者我需要让Forever工作吗? If so, any idea as to the error I got? 如果是的话,对我得到的错误有任何想法吗?

Yes, OpenShift does automatically restart your Node app when it crashes. 是的,OpenShift会在崩溃时自动重启您的Node应用程序。 OpenShift doesn't use forever.js but it uses node-supervisor . OpenShift不使用forever.js,但它使用node-supervisor Your can test it by requiring something that doesn't exist. 您可以通过要求不存在的东西来测试它。 Fix it quick though because the log can grow fast restarting the app. 尽快修复它,因为日志可以快速重新启动应用程序。 Here is the log in nodejs.log on OpenShift which shows that it's running node-supervisor: 这是OpenShift上的nodejs.log登录,显示它正在运行node-supervisor:

DEBUG: Running node-supervisor with
DEBUG:   program 'server.js'
DEBUG:   --watch '/var/lib/openshift/53a9e06ae0b8cde26300008e/app-root/data/.nodewatch'
DEBUG:   --ignore 'undefined'
DEBUG:   --extensions 'node|js|coffee'
DEBUG:   --exec 'node'
DEBUG: Starting child process with 'node server.js'
DEBUG: Watching directory '/var/lib/openshift/53a9e06ae0b8cde26300008e/app-root/data/.nodewatch' for changes.

Currently, OpenShift's default behavior involves using supervisor to start, watch, and restart your nodejs applications. 目前,OpenShift的默认行为涉及使用supervisor来启动,监视和重新启动nodejs应用程序。

Here is a quick outline of the various init options for nodejs: 以下是nodejs的各种init选项的快速概述:

  1. If your app includes a valid package.json file with a main entry ( containing the name of your server script ), then OpenShift will initialize your app by using supervisor to start that script. 如果您的应用程序包含带有main条目的有效package.json文件( 包含服务器脚本的名称 ),则OpenShift将使用supervisor初始化您的应用程序以启动该脚本。
  2. If your app includes the force_npm_deploy marker file (an empty file in .openshift/markers/use_npm ) - then OpenShift will just run npm start . 如果你的应用包含force_npm_deploy标记文件.openshift/markers/use_npm的空文件) - 那么OpenShift将只运行npm start This runs whatever is defined in your package.json file's scripts.start entity. 这将运行package.json文件的scripts.start实体中定义的任何内容。
  3. If all else fails, OpenShift will try to run server.js using supervisor (as a fallback option). 如果所有其他方法都失败了,OpenShift将尝试使用supervisor运行server.js (作为后备选项)。

Some additional notes are available here: https://www.openshift.com/blogs/10-reasons-openshift-is-the-best-place-to-host-your-nodejs-app#npm 这里有一些额外的注释: https//www.openshift.com/blogs/10-reasons-openshift-is-the-best-place-to-host-your-nodejs-app#npm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM