eiquidus icon indicating copy to clipboard operation
eiquidus copied to clipboard

How to create a Systemd service for start

Open ghost opened this issue 1 year ago • 3 comments

what would be the correct method to start "npm run start-pm2" on linux using systemd? Thank you.

ghost avatar Oct 19 '24 15:10 ghost

I took a quick look at this but unfortunately doesn't seem trivial to do. If you want to experiment with this yourself the full cmd that gets run when starting pm2 is:

cd /path/to/explorer && export NODE_ENV=production && ./node_modules/pm2/bin/pm2 start ./bin/instance -i 0 -n explorer -p "./tmp/pm2.pid" --node-args="--stack-size=10000" --update-env

I actually didn't try systemd but tried to add a crontab and it doesn't seem to work as expected. When you run the cmd manually it works although it breaks pm2 if you try to use npm run start-pm2 afterwards which requires a reboot to fix and it will get reinstalled again after running npm run start-pm2 which does some extra processing to check and install pm2 again if not found.

For now, this isn't supported and would likely require some rewrites to the prestart.js to pass in the full pm2 path at the very least.

I'll have to look at this sometime in the future, but it's very low priority on my list since it's easy enough to start it manually and I typically don't reboot my production machine.

If you plan to look at it yourself, let us know if you are successful and I can add a note in the README on how it can be done for those that are interested.

joeuhren avatar Oct 21 '24 03:10 joeuhren

That looks promising thank you very much for the lead, if I get it working I will report here.

Are you using cronjob instead?

ghost avatar Oct 22 '24 20:10 ghost

Are you using cronjob instead?

I'm only using crontab for running the sync scripts, not for starting the webserver. I just manually start the webserver after a reboot if need be. It's never been an issue for me.

joeuhren avatar Oct 24 '24 23:10 joeuhren