简体   繁体   English

在后台运行Webrick服务器?

[英]Running Webrick server in background?

MBPro:shovell myname$ ruby script/server
=> Booting WEBrick
=> Rails 2.3.8 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-08-01 15:28:35] INFO  WEBrick 1.3.1
[2010-08-01 15:28:35] INFO  ruby 1.9.1 (2010-07-02) [i386-darwin10.4.0]
[2010-08-01 15:28:35] INFO  WEBrick::HTTPServer#start: pid=36349 port=3000

After this command, I have to keep the terminal open, can't even get out using Cmd+z. 在这个命令之后,我必须保持终端打开,甚至不能使用Cmd + z。 Can't I run it as a background service? 我不能把它作为后台服务运行吗?

Thanks 谢谢

输出已经给你答案:

=> Call with -d to detach

In general, you can use: 一般来说,你可以使用:

command &

And it will detach from the terminal window. 它将从终端窗口分离。

If you are using Linux, another options is to use screen : 如果您使用的是Linux,则另一个选择是使用screen

screen
# start your process
# press Ctrl+a
# press Ctrl+d

Voila! 瞧! It's detached. 它是分离的。 Then you can call screen -r and your process will be back as if nothing happened. 然后你可以调用screen -r ,你的进程就会回来,好像什么都没发生一样。

If you run rails s --help You will see a bunch of options 如果你运行rails s --help你会看到一堆选项

Usage: rails server [mongrel, thin etc] [options]
    -p, --port=port                  Runs Rails on the specified port.
                                     Default: 3000
    -b, --binding=IP                 Binds Rails to the specified IP.
                                     Default: localhost
    -c, --config=file                Uses a custom rackup configuration.
    -d, --daemon                     Runs server as a Daemon.
    -u, --debugger                   Enables the debugger.
    -e, --environment=name           Specifies the environment to run this server under (test/development/production).
                                     Default: development
    -P, --pid=pid                    Specifies the PID file.
                                     Default: tmp/pids/server.pid

    -h, --help                       Shows this help message.

The one that you need is to run it as a Daemon. 您需要的是将其作为守护进程运行。 Hence, the solution is: rails s -d 因此,解决方案是: rails s -d

The mongrel gem can do this easy. 杂种宝石可以很容易地做到这一点。

gem install mongrel

Then you should be able to use 然后你应该可以使用

mongrel_rails start -d

-d for daemon mode. -d用于守护进程模式。

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

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