Pm2 Start not starting on Ubuntu

It is difficult for me to get pm2 to restart (itself and two node / express files, app.js and app2.js ) when the server reboots.

The following are the processes I tried:

 pm2 startup pm2 start app.js pm2 start app2.js pm2 startup ubuntu (also tried systemd and with/without -u username) pm2 save 

I ran the above commands in all possible combinations, and nothing worked. I tried working as root, and it did not work either.

My ~/.pm2/dump.pm2 contains information, so I'm not sure where else to look.

I tried to modify the /etc/init.d/pm2-init.sh file to suit this problem , but that did not help.

My setup:
Digital ocean server
Ubuntu 15.10
Node v5.4.1
PM2 v 1.0.0

Other links I tried ..
http://pm2.keymetrics.io/docs/usage/startup/
https://www.digitalocean.com/community/tutorials/how-to-use-pm2-to-setup-a-node-js-production-environment-on-an-ubuntu-vps
https://gist.github.com/leommoore/5998406
https://www.terlici.com/2015/06/20/running-node-forever.html
https://serversforhackers.com/node-process-management-with-pm2 http://nodered.org/docs/getting-started/running.html#starting-node-red-on-boot
https://github.com/Unitech/pm2/issues/1316

Until now, every time I restart the server, pm2 does not start automatically (if I do not need to wait a few minutes? - nginx restarts instantly).

Can someone help me with this? What is the order of execution of the commands? Do I need to modify any additional files?

+7
source share
4 answers

You must save your node application using

  pm2 start [app_name] pm2 save 

Then do:

  pm2 startup [operation system] 

This will create the dump.pm2 file, which pm2 needs to run the application on reboot.

Operating system:

  • systemd : Ubuntu> = 16, CentOS> = 7, Arch, Debian> = 7
  • upstart : Ubuntu <= 14
  • Launch : Darwin, MacOSx
  • openrc : Gentoo Linux, Arch Linux
  • rcd : FreeBSD
  • systemv : Centos 6, Amazon Linux
+6
source

I think I solved the problem

I played with pm2 and found two working paths for CentOS 7 (in your project folder index.js is the main file):

  • 1

      sudo pm2 start index.js
     sudo pm2 save
     sudo pm2 startup centos
    
  • 2

      pm2 start index.js
     pm2 save
     pm2 startup centos
     '# and run the script generated in the previous code under sudo
    
+2
source

Have you tried checking your boot logs on Ubuntu ( cat /var/log/boot.log )?

You will probably see an error, for example:

Error: EACCES, permission denied '/home/<USER>/.pm2'

I could not solve this problem myself, but at least it should point you in the right direction.

+1
source

The solution for me was to restart pm2 using systemctl: systemctl reload-or-restart pm2-root

When I first set up my Ubuntu 18.04 server, I started pm2 start app.js to start my application. Then, when I tried to run pm2 startup + pm2 save to restart the application at boot time, this did not seem to work, since when starting systemctl list-units systemctl pm2 did not appear in the list of services. Even though the application has pm2 list ( pm2 list confirmed this). So I ran systemctl list-units -all , and pm2 was shown as "inactive" and "dead."

So I did:

  • systemctl status pm2-root (just to confirm that it was "inactive" / "dead")

  • systemctl reload-or-restart pm2-root (to restart pm2 via systemctl)

  • systemctl status pm2-root (to confirm that pm2 is now β€œactive” / β€œworking”)

  • Then I also launched systemctl enable pm2-root to start PM2 at startup (not sure if necessary)

  • And pm2 startup + pm2 save again (to start at boot)

OBS .: I used pm2-root in my commands since I started pm2 with the root , but you should replace it ( pm2-<USER> ) if necessary.

0
source

Source: https://habr.com/ru/post/1240734/


All Articles