14
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

执行此命令后,我必须保持终端打开,甚至无法使用 Cmd+z 退出。我不能将它作为后台服务运行吗?

谢谢

4

4 回答 4

38

输出已经给了你答案:

=> Call with -d to detach
于 2010-08-01T10:11:01.843 回答
6

一般来说,您可以使用:

command &

它将与终端窗口分离。

如果您使用的是 Linux,另一种选择是使用screen

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

瞧!它是分离的。然后你可以打电话screen -r,你的过程会回来,就好像什么都没发生一样。

于 2010-08-01T10:15:38.873 回答
2

如果你运行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.

您需要的是将其作为守护程序运行。因此,解决方案是: rails s -d

于 2016-01-13T05:41:15.003 回答
1

杂种宝石可以轻松做到这一点。

gem install mongrel

然后你应该可以使用

mongrel_rails start -d

-d用于守护程序模式。

于 2010-08-01T10:14:52.333 回答