简体   繁体   中英

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

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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