gpt4 book ai didi

node.js - 如何让 Node 服务器永久保持事件状态?

转载 作者:太空宇宙 更新时间:2023-11-04 05:08:37 24 4
gpt4 key购买 nike

我尝试了很多方法来让 Node 服务器在 Linux 环境中保持事件状态,但没有任何效果。有时服务器仅运行 4-5 小时,有时运行 10-12 小时,之后服务器会自动关闭。我尝试过forever start、pm2、nodemon,但没有任何效果。我还尝试过使用永远启动的 shell 脚本来运行它,但这也不起作用。

最佳答案

Applications that are running under PM2 will be restarted automatically if the application crashes or is killed, but an additional step needs to be taken to get the application to launch on system startup (boot or reboot). Luckily, PM2 provides an easy way to do this, the startup subcommand.

The startup subcommand generates and configures a startup script to launch PM2 and its managed processes on server boots:

$ pm2 startup systemd

Run the command that was generated (similar to the highlighted output above, but with your username instead of sammy) to set PM2 up to start on boot (use the command from your own output):

sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u sammy --hp /home/sammy

查看此处了解详细信息 https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

您可以增加内存重新启动的大小 - 检查此:pm2 process crashed on server. it gives an error

关于node.js - 如何让 Node 服务器永久保持事件状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58230658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com