How to start rails server in background

When I run ruby โ€‹โ€‹script script/server -e test , it runs on the console. When I close the console, it also stops the process. I want to start the server in the background. How can i do this?

+8
ruby-on-rails
source share
6 answers

You can run it as a daemon using script/server -d

+19
source share

If you use thin:

rails server thin -d

And to stop him:

kill -9 $(cat tmp/pids/server.pid)

+19
source share

Its a little late to answer. But that would be good for the future person.

The easiest and fastest way to put rails (or any service in the background), assuming it has a Unix / Linux OS

$ nohup rails server &

This can be used for any service, such as

$ nohup <service command> &

+10
source share

Start the server with & at the end:

 script/server -e test& 

It will be placed in the background.

Or you can use another server as thin: http://code.macournoyer.com/thin/

 (sudo) gem install thin 

And then start and stop it using

 thin start thin stop 
+3
source share

One way to do this, which even stays connected to ssh, is to use Screen, which makes an additional terminal that your current console does not affect. sudo apt-get install screen open screen screen Then run rails server & . & just makes it run the background. To stop it, enter kill -9 # , where # is the number it gives you when it starts.

Press "Crtl + A" to exit and enter screen -r to return to the screen terminal.

+2
source share

Another option is to use apache with the passenger, it is very easy to configure it, and after you have done this, as soon as you can use it for all other applications. Plus, this is likely to be close to what you use in production, so thereโ€™s another advantage.

If you're on a Mac, you can also get a passenger preference panel that simplifies apache configuration steps.

0
source share

Source: https://habr.com/ru/post/649751/


All Articles