如何将Node.js作为后台进程运行并且永不消亡? [英] How to run Node.js as a background process and never die?

查看:98
本文介绍了如何将Node.js作为后台进程运行并且永不消亡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过腻子SSH连接到linux服务器.我试图将其作为这样的后台进程运行:

$ node server.js &

但是,在2.5小时后,终端变为非活动状态,并且该过程终止.无论如何,即使在终端断开连接的情况下,我仍然可以保持该过程正常运行吗?


编辑1

实际上,我尝试了nohup,但是,一旦我关闭Putty SSH终端或拔出Internet插头,服务器进程就会立即停止.

在腻子里我有什么需要做的吗?


编辑2(2012年2月发布)

有一个node.js模块,永远.它将作为守护程序服务运行node.js服务器.

解决方案

简单解决方案(如果您对返回该过程不感兴趣,只希望它继续运行):

nohup node server.js &

还有jobs命令可以查看这些后台进程的索引列表.而且,您可以通过运行kill %1kill %2来杀死后台进程,而数字是该进程的索引.

强大的解决方案(如果它是交互式的,则允许您重新连接到该过程):

screen

然后可以通过按Ctrl + a + d进行分离,然后通过运行screen -r

进行附加

还考虑使用屏幕替代品tmux.

I connect to the linux server via putty SSH. I tried to run it as a background process like this:

$ node server.js &

However, after 2.5 hrs the terminal becomes inactive and the process dies. Is there anyway I can keep the process alive even with the terminal disconnected?


Edit 1

Actually, I tried nohup, but as soon as I close the Putty SSH terminal or unplug my internet, the server process stops right away.

Is there anything I have to do in Putty?


Edit 2 (on Feb, 2012)

There is a node.js module, forever. It will run node.js server as daemon service.

解决方案

Simple solution (if you are not interested in coming back to the process, just want it to keep running):

nohup node server.js &

There's also the jobs command to see an indexed list of those backgrounded processes. And you can kill a backgrounded process by running kill %1 or kill %2 with the number being the index of the process.

Powerful solution (allows you to reconnect to the process if it is interactive):

screen

You can then detach by pressing Ctrl+a+d and then attach back by running screen -r

Also consider the newer alternative to screen, tmux.

这篇关于如何将Node.js作为后台进程运行并且永不消亡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆