I run a webserver on a LAMP stack, which includes a secondary Node.js server running on localhost that some requests get passed off to. I normally start/restart this process manually, using these 3 commands:
cd /var/www/html/connect
node secondaryServer.js &> output.log &
disown
I’m trying to migrate this set of commands to a bash script (eventually to be called remotely, via PHP, so I can re-start the Node.js server via an Admin console on the website), so that I just have to call one file instead of typing each line in each time. But I can’t seem to get it to work where the Node process survives the end of the script.
Most resources I’ve seen just mention needing to start it in the background, which I’m already doing with the & (to the best of my knowledge).
I’m struggling to debug this, as I don’t really get any meaningful output aside from knowing that the new process isn’t still alive when the script concludes.
Any advice on how to get this Node process to survive properly?
I tried merging the ‘disown’ command with the ‘node’ command like this:
disown node secondaryServer.js &> output.log &
But that also didn’t work.