简体   繁体   English

为什么注销后永远无法使nodejs进程运行?

[英]Why is forever not working to keep my nodejs process running after I logout?

I set up an Ubuntu Server in my home for the purpose of hosting a web application served by nodejs. 我在家里设置了一个Ubuntu服务器,用于托管由nodejs服务的Web应用程序。 I have a connect app on my server. 我的服务器上有一个连接应用程序。 When I ssh in and just do something like 当我进去并做类似的事情时

node app.js &> server.log &
logout

Then after I logout the server is like put on hold, and it will not serve any requests, but when I ssh back in it starts to serve requests again. 然后,我注销后,服务器就像被搁置一样,它将不处理任何请求,但是当我重新登录时,它将再次开始处理请求。

So it looks like the forever package is designed to solve this problem. 因此,看起来永久包装旨在解决此问题。 So installed forever and am doing this: 所以永远安装并执行此操作:

forever start -al forever.log -ao serverout.log -ae servererror.log app.js

I get the same results from this command. 我从此命令得到相同的结果。 My server will serve requests while I'm ssh'ed in, but once I logout my server stops serving requests. SSH进入时,我的服务器将处理请求,但是注销后,服务器将停止处理请求。 What else can I do to troubleshoot this? 我还可以做些什么来解决这个问题?

Consider using cron . 考虑使用cron You can run crontab in bash with no options to get the cron configuration for your account. 您可以在不带任何选项的bash中运行crontab来获取您帐户的cron配置。 You may need root access, and then have to specify the user account using the -u option. 您可能需要root用户访问权限,然后必须使用-u选项指定用户帐户。 See man crontab for more information about your distribution's implementation. 有关发行版实施的更多信息,请参见man crontab

I'm sure there are better out there, but this is a decent tutorial on cron's grammar. 我敢肯定有更好的在那里,但是是对的cron的语法一个体面的教程。

I wouldn't use Forever for this but production-ready tools like Supervisord with Monit, see Running and managing nodejs applications on single server . 我不会为此使用Forever,而是要使用具有Monit功能的 Supervisord等生产就绪型工具,请参阅在单个服务器上运行和管理nodejs应用程序

For each of your application just create a Supervisor configuration file like this: 对于每个应用程序,只需创建一个Supervisor配置文件,如下所示:

[program:myapp]
command=node myapp.js                   ; the program (relative uses PATH, can take args)
directory=/www/app/                     ; directory to cwd to before exec (def no cwd)
process_name=myapp                      ; process_name expr (default %(program_name)s)
autorestart=true                        ; whether/when to restart (default: unexpected)
startsecs=1                             ; number of secs prog must stay running (def. 1)
stopwaitsecs=10                         ; max num secs to wait b4 SIGKILL (default 10)
stdout_logfile=/var/log/myapp.log       ; stdout log path, NONE for none default AUTO
stderr_logfile=/var/log/myapp.err.log   ; stderr log path, NONE for none default AUTO

More informations: NodeJS process management at Brin.gr . 更多信息: Brin.gr上的NodeJS流程管理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM