我很难在服务器重新启动时让pm2重新启动(本身和两个节点/快速文件,app.js&app2.js).
以下是我尝试过的流程:
pm2 startup
pm2 start app.js
pm2 start app2.js
pm2 startup ubuntu (also tried systemd and with/without -u username)
pm2 save
Run Code Online (Sandbox Code Playgroud)
我在每种可能的组合中运行上述命令,但没有任何效果.我尝试以root身份运行,但它也无法运行.
我的~/.pm2/dump.pm2文件包含信息,所以我不确定在哪里查看.
我试图/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 /耀华/ PM2 /问题/ 1316
到目前为止,每次重启服务器时,pm2都无法自动启动(除非我需要等待几分钟? - nginx立即重启).
有人可以帮我解决这个问题吗?命令应该运行的顺序是什么?我是否需要修改任何其他文件?
小智 7
您必须使用保存节点应用程序
pm2 start [app_name]
pm2 save
Run Code Online (Sandbox Code Playgroud)
然后做:
pm2 startup [operation system]
Run Code Online (Sandbox Code Playgroud)
这将创建一个dump.pm2文件,pm2需要在重新启动时运行您的应用程序.
我的解决方案是使用systemctl重新启动 pm2 :systemctl reload-or-restart pm2-root
当我第一次设置 Ubuntu 18.04 服务器时,我跑去pm2 start app.js启动我的应用程序。然后,当我尝试运行pm2 startup+pm2 save在启动时重新启动应用程序时,这似乎不起作用,因为通过运行systemctl list-units, pm2 没有\xe2\x80\x99t 显示在服务列表中。即使应用程序正在运行(pm2 list证实了这一点)。所以我跑了systemctl list-units -all,pm2显示为\xe2\x80\x9cinactive\xe2\x80\x9d和\xe2\x80\x9cdead\xe2\x80\x9d。
所以我做了:
\n\nsystemctl status pm2-root(只是为了确认它是“不活动”/“死亡”)
systemctl reload-or-restart pm2-root(通过systemctl重新启动 pm2 )
systemctl status pm2-root(确认 pm2 现在是 \xe2\x80\x9cactive\xe2\x80\x9d/\xe2\x80\x9crunning\xe2\x80\x9d)
然后我还运行了systemctl enable pm2-root, 以使 PM2 在启动时运行(不确定是否有必要)
再次pm2 startup+ pm2 save(用于启动时启动)
OBS.:我pm2-root在命令中使用了,因为我正在使用用户运行 pm2 ,但如果需要,root您应该替换为您的用户 ( )。pm2-<USER>
| 归档时间: |
|
| 查看次数: |
6582 次 |
| 最近记录: |