Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu 14.04 - pm2 startup not starting after reboot

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!

like image 340
Max Avatar asked Sep 24 '15 19:09

Max


Video Answer


2 Answers

What steps work for me on Ubuntu 18.04.4

  1. npm i pm2 -g
  2. run this command as root user: pm2 startup
    • creates service pm2-root found in /etc/systemd/system
  3. systemctl enable pm2-root, service pm2-root status
    • Note: after Node upgrade, run these commands as root: pm2 unstartup, pm2 startup; documentation
  4. pm2 start dist\index.js --name YourNodeApp
  5. pm2 save
  6. reboot
  7. pm2 ls should show your YourNodeApp online
like image 125
xinthose Avatar answered Sep 28 '22 02:09

xinthose


Basically,

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

like image 22
Mohammad Zaid Pathan Avatar answered Sep 28 '22 02:09

Mohammad Zaid Pathan