team-exor / eiquidus

Feature-rich open-source altcoin block explorer. Regular Updates ~ Platform Independent ~ Mobile Friendly ~ Supports Themes, Markets, Charts, Claiming Addresses, Public API's, Custom RPC Cmds, Bitcoin, Heavycoin, zk-SNARKs ~ List Masternodes, Network Peers, Top 100 Wallets ~ Built-in Update Script ~ Highly Customizable
https://explorer.exor.io
BSD 3-Clause "New" or "Revised" License
89 stars 186 forks source link

How to create a Systemd service for start #49

Open realsetvin opened 1 month ago

realsetvin commented 1 month ago

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

joeuhren commented 1 month ago

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.

realsetvin commented 1 month ago

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

Are you using cronjob instead?

joeuhren commented 1 month ago

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.