Forever.js启动和重新启动多个脚本 [英] Forever.js starting and restarting multiple scripts

查看:682
本文介绍了Forever.js启动和重新启动多个脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络应用程序有3个主要的node.js组件:网站,Feed和作业。

My web app has 3 main node.js components: website, feeds and jobs.

要开始这些,我将永远使用:

To start these I am using forever:

//forever.js

var forever = require('forever');

function start(name){

  forever.start( ['coffee', name + '.coffee'], { /* log options */ } )

};

start('website');
start('feeds');
start('jobs');

我第一次注意到,如果我运行脚本,它不会作为守护进程运行它。 (最可能是正常的)

What I first noticed is that if I run script it wont run it as a daemon. ( Which is most likely normal )

node forever.js

所以我以后做的是永远运行forever.js脚本。我不知道这是否正确,还有一个forever.startDaemon,所以不知道我应该使用哪一个。

So what I did next was run the forever.js script with forever. I am not sure if this is correct, there is also a forever.startDaemon so not sure which one I should use.

forever start forever.js

这是有效的,但问题是我想重新启动所有进程,当我的应用程式的新版本已发布。我正在使用git的接收后钩来首次运行forever.js,但是如果我在每个后收到的时候这样做,它每次只会产生3个进程。

This works but the problem is that I would like to restart all the processes when a new version of my app is published. I am using git's post-receive hook to run the forever.js the first time but if I do this on each post-recieve it will just spawn 3 processes each time.

所以我想我需要一种方法来重新启动3个进程,如果它们已经在运行。我以为用forever.list这样做,但文档只能说:

So I guess I need a way to restart 3 processes if they are already running. I thought to do this with forever.list but the documentation only say:

forever.list (format, callback)

Returns a list of metadata objects about each process that is being run using 
forever. This method is synchronous and will return the list of metadata as such.
Only processes which have invoked forever.startServer() will be available from
forever.list()

首先我不知道什么格式的意思,第二次它期望一个回调,但它说它的同步。这是一个有点混乱,我不知道如何使用列表。

First of all I am not sure what format means and second it expects a callback but then it says its synchronous. Which is a little confusing and I am not sure how to use list.

最后我想做的是启动/重新启动3 node.js进程在git的帖子 - 接收钩。

In the end all I want to do is start/restart 3 node.js processes on git's post-receive hook.

推荐答案

我认为最好的方法是:

forever start website.js
forever start feeds.js
forever start jobs.js

然后在您的git后接收挂钩中:

and then in your git post-receive hook:

forever restart website.js
forever restart feeds.js
forever restart jobs.js

将这些节点进程包含在一个进程中并不是一个好主意。我现在亲自使用监督与监狱,而不是永远( supervisord比起永远的IMHO更稳定和更强大)。

Wrapping these node processes inside a single process is not a good idea. I now personally use Supervisord with monit instead of forever (supervisord is more stable & powerful than forever IMHO).

这篇关于Forever.js启动和重新启动多个脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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