I have written a NodeJS service, that will run continuously. I want to run two copies of it using PM2.
I am also trying to write an upstart script for it, and I couldn't make it work (basically stop
wouldn't work, the PID was never correct.
I read a bit on upstart's expect
stanza, which tells upstart whether the service forks zero times, once or twice, and I realized that PM2 forks 4 times and then ends, so there is no PID for upstart to kill to stop the process.
Should I just abandon upstart and write a different kind of startup script for my service?
After snooping around, I think I can answer my own question: no, upstart isn't suitable for this kind of task, it needs one PID that it can kill to bring the service down. In the case of PM2, there is no such PID, and also, the way to "stop" the service isn't to kill one process, but to run one (pm2 stop all
or pm2 kill
). So, I fell back to pm2's own generated bash startup script.