首页 文章

pm2启动没有在Ubuntu上启动

提问于
浏览
7

我很难在服务器重新启动时让pm2重新启动(本身和两个节点/快速文件, app.jsapp2.js ) .

以下是我尝试过的流程:

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

我在每种可能的组合中运行上述命令,但没有任何效果 . 我尝试以root身份运行,但它也无法运行 .

我的 ~/.pm2/dump.pm2 文件包含信息,所以我不确定在哪里查看 .

我试图根据this issue修改我的 /etc/init.d/pm2-init.sh 文件,但它没有帮助 .

我的设置:
数字海洋服务器
Ubuntu 15.10
节点v5.4.1
PM2 v 1.0.0

其他参考我试过..
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

到目前为止,每次重启服务器时,pm2都无法自动启动(除非我需要等待几分钟? - nginx立即重启) .

有人可以帮我解决这个问题吗?命令应该运行的顺序是什么?我是否需要修改任何其他文件?

4 回答

  • 0

    您必须使用保存节点应用程序

    pm2 start [app_name]
     pm2 save
    

    然后做:

    pm2 startup [operation system]
    

    这将创建一个dump.pm2文件,pm2需要在重新启动时运行您的应用程序 .

  • 2

    我想我solved the problem

    我玩pm2,发现CentOS 7的两种工作方式(在你的项目文件夹中的index.js - 主文件):1 sudo pm2 start index.js
    sudo pm2保存
    sudo pm2启动centos
    2 pm2开始index.js
    pm2保存
    pm2启动centos
    '#并在sudo下运行上一代码中生成的脚本

  • 5

    您是否尝试在Ubuntu( cat /var/log/boot.log )上检查启动日志?

    您可能会看到如下错误:

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

    我自己无法解决这个问题,但至少这应该指向正确的方向 .

  • 1

    我的解决方案是使用systemctl重新启动pm2: systemctl reload-or-restart pm2-root

    当我第一次设置我的Ubuntu 18.04服务器时,我运行 pm2 start app.js 来启动我的应用程序 . 然后,当我尝试运行 pm2 startup pm2 save 以在启动时重新启动应用程序时,这似乎无法正常工作,因为通过运行 systemctl list-units ,pm2没有显示在服务列表中 . 即使该应用程序正在运行( pm2 list 确认) . 所以我跑了 systemctl list-units -all ,pm2显示为“无效”和“死” .

    所以我做了:

    • systemctl status pm2-root (只是为了确认它是"inactive" / "dead")

    • systemctl reload-or-restart pm2-root (通过systemctl重启pm2)

    • systemctl status pm2-root (确认pm2现在处于“活动”/“正在运行”)

    • 然后我也运行了 systemctl enable pm2-root ,以启用PM2在启动时运行(如果需要,不确定)

    再次

    • pm2 startup pm2 save (开机时启动)

    OBS . :我在我的命令中使用了 pm2-root ,因为我用 root 用户运行了pm2,但如果需要,你应该替换你的用户( pm2-<USER> ) .

相关问题