简体   繁体   English

从PHP优雅/强制重启NodeJS(与Forever一起运行)

[英]Restart gracefully/forcefully NodeJS (running with Forever) from PHP

I have 10 NodeJS servers running on 10 separate machines. 我有10台NodeJS服务器在10台单独的计算机上运行。

They are running with Forever, which keeps them up if they crash, and restarts them if a file changes. 它们与Forever一起运行,如果它们崩溃,它们将保持运行状态;如果文件发生更改,则将它们重新启动。

I would like to restart them by clicking on a button in an HTML page. 我想通过单击HTML页面中的按钮来重新启动它们。 Because nodeJS isn't open to the external world, but only accessible from within the machines, I would like to use a PHP script as a "bridge" between the external world and Node. 因为nodeJS不向外部世界开放,而只能从机器内部访问,所以我想使用PHP脚本作为外部世界和Node之间的“桥梁”。 The button would send a POST request to a PHP script, which could then in some way tell Forever to restart the NodeJS process. 该按钮会将POST请求发送到PHP脚本,然后可以以某种方式告诉Forever重新启动NodeJS进程。

First question, do I need to have a PHP script on each server, and to ask each one of those scripts to restart NodeJS on its own machine ? 第一个问题,我是否需要在每个服务器上都有一个PHP脚本,并要求这些脚本中的每个脚本在其自己的计算机上重新启动NodeJS? Or can I have one server with a PHP script which could in someway notify all the servers (I know their local IPs of course) to restart their NodeJS processes ? 还是我可以有一台带有PHP脚本的服务器,该服务器可以以某种方式通知所有服务器(我当然知道它们的本地IP)以重新启动其NodeJS进程?

I thought about doing this by sending process signals, but of course I cannot do that over a network. 我曾考虑过通过发送过程信号来做到这一点,但是我当然不能通过网络来做到这一点。

What do you think ? 你怎么看 ?

I ended up using the Watch option in Forever which listens for file changes in the folder. 我最终使用了Forever中的“监视”选项,该选项侦听文件夹中的文件更改。 The restart button updates a "timestamp" file, which causes forever to restart. 重新启动按钮将更新“时间戳”文件,这将导致永远重新启动。 Because of NFS replication, this is propagated to all the machines. 由于使用NFS复制,因此会将其传播到所有计算机。 Not the best solution I guess, it works, but I would gladly do something better 我猜这不是最好的解决方案,它可以工作,但是我很乐意做得更好

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

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