pm2 Startup not starting up on Ubuntu

主宰稳场 提交于 2019-11-30 19:18:24
Michael Rechenberg

You have to save your node app using

 pm2 start [app_name]
 pm2 save

Then do:

 pm2 startup [operation system]

This will create a dump.pm2 file that pm2 needs to run your app on reboot.

Operation system:

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

I think I solved the problem

I played with pm2, and found two working way for CentOS 7 (in your project folder index.js - 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
    

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

You probably see an error like:

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

I haven't been able to solve this issue myself but at least this should point you in the right direction.

The solution for me was restarting pm2 with systemctl: systemctl reload-or-restart pm2-root

When I setup my Ubuntu 18.04 server on the first time, I ran pm2 start app.js to start my app. Then when I tried to run pm2 startup + pm2 save to restart the app on boot, this seemed to be not working, as by running systemctl list-units, pm2 didn’t show up in the services list. Even though the app was running (pm2 list confirmed that). So I ran systemctl list-units -all, and pm2 showed 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 through systemctl)

  • systemctl status pm2-root (to confirm that pm2 now was “active”/“running”)

  • Then I also ran systemctl enable pm2-root, to enable PM2 to run on startup (not sure if necessary)

  • And pm2 startup + pm2 save again (for the start on boot)

OBS.: I used pm2-root in my commands, as I was running pm2 with root user, but you should replace for your user (pm2-<USER>), if needed.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!