Ruby-on-rails 如何在后台启动rails服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4334403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to start rails server in background
提问by Usman Ali
When I run ruby script/server -e test, it runs on console. When I close the console, it also stops the process. I want to run the server in background. How can I do this?
当我运行 ruby 时script/server -e test,它在控制台上运行。当我关闭控制台时,它也会停止该过程。我想在后台运行服务器。我怎样才能做到这一点?
回答by vise
You can run it as a daemon with script/server -d
您可以将它作为守护进程运行 script/server -d
回答by Kryptman
If you are using thin:
如果您使用的是瘦:
rails server thin -d
rails server thin -d
And, in order to stop it:
而且,为了阻止它:
kill -9 $(cat tmp/pids/server.pid)
kill -9 $(cat tmp/pids/server.pid)
回答by iankits
Its a bit late to answer. But it would be good for future person.
回答有点晚了。但这对未来的人有好处。
The easiest and quicker way to put rails (or any service in background) assuming it to have Unix/Linux OS
假设它具有 Unix/Linux 操作系统,将 Rails(或任何服务置于后台)的最简单快捷的方法
$ nohup rails server &
$ nohup rails server &
This can be used for any service like this
这可以用于任何这样的服务
$ nohup <service command> &
$ nohup <service command> &
回答by mvndaai
One way to do this, which even stays connected on ssh is use Screen, which makes a sub terminal that isn't affected by your current console. sudo apt-get install screenOpen screen screenThen start rails rails server &. The &just makes it run it the background. To stop it type kill -9 #where #is the number it gives you when you start it.
一种甚至在 ssh 上保持连接的方法是使用 Screen,它使子终端不受当前控制台的影响。sudo apt-get install screen打开屏幕screen然后启动 rails rails server &。该&只是使它运行它的背景。要停止它,请键入启动它时它给你的数字kill -9 #在哪里#。
Press 'Crtl + A' to escape and type screen -rto get back in to the screen terminal.
按“Crtl + A”screen -r退出并输入以返回屏幕终端。
回答by tjeden
Run your server with &at the end:
最后运行你的服务器&:
script/server -e test&
It will put it to background.
它会将其置于背景中。
Or you can use other server like thin: http://code.macournoyer.com/thin/
或者您可以使用其他服务器,如瘦:http: //code.macournoyer.com/thin/
(sudo) gem install thin
And then start and stop it using
然后开始和停止它使用
thin start
thin stop
回答by jonnii
The other option is to use apache with passenger, it's really easy to set up and once you've done it once you can use it for all your other apps. Plus it's most likely going to be near to what you're running on production, so that's another benefit.
另一种选择是将 apache 与乘客一起使用,它非常容易设置,一旦完成,您就可以将其用于所有其他应用程序。此外,它很可能会接近您在生产中运行的内容,因此这是另一个好处。
If you're on a mac you can also get the passenger preference pane which simplifies the apache configuration steps.
如果您使用的是 mac,您还可以获得乘客偏好面板,它简化了 apache 配置步骤。

