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

寵の児 提交于 2019-12-12 04:52:39

问题


I have 10 NodeJS servers running on 10 separate machines.

They are running with Forever, which keeps them up if they crash, and restarts them if a file changes.

I would like to restart them by clicking on a button in an HTML page. 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. The button would send a POST request to a PHP script, which could then in some way tell Forever to restart the NodeJS process.

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 ? 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 ?

I thought about doing this by sending process signals, but of course I cannot do that over a network.

What do you think ?


回答1:


I ended up using the Watch option in Forever which listens for file changes in the folder. The restart button updates a "timestamp" file, which causes forever to restart. Because of NFS replication, this is propagated to all the machines. Not the best solution I guess, it works, but I would gladly do something better



来源:https://stackoverflow.com/questions/26906698/restart-gracefully-forcefully-nodejs-running-with-forever-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!