I am using pm2 to start a node.js process, and I would like this process to be started automatically when the system (Ubuntu 14.04 on Intel Atom processor) is booted. I have followed the instructions on the pm2 web site but without success. My dump.pm2 appears to be correct, but the pm2 daemon is never started. I have tried both the ubuntu and linux options to pm2 startup, as well as autodetect, both with and without a specified user. Files (links) S20pm2-init.sh have been created in /etc/rc[2-5].d but nothing gets started. I can't find find any obvious error messages in the system log.
Any ideas?
Edit to add
I find that
service pm2-init.sh start starts the daemon correctly, when run from my login account, which is the same as that defined by USER= in the file /etc/init.d/pm2-init.sh. I've made sure the PM2_HOME definition in this file points to the correct place as well. However, it still doesn't start on system boot!
What steps work for me on Ubuntu 18.04.4
npm i pm2 -gpm2 startup
pm2-root found in /etc/systemd/system
systemctl enable pm2-root, service pm2-root status
pm2 unstartup, pm2 startup; documentation
pm2 start dist\index.js --name YourNodeApppm2 saverebootpm2 ls should show your YourNodeApp onlineBasically,
Step 1: Run following command,
pm2 startup
Here you will get 1 command generated, copy/paste it and done.
(Sample command you will get from above step: sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu)
Ref
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With