19

To run the Rails server, I use $rails server. It says 'To stop, click Ctrl+c'. I use Putty.

The questions are:

  1. Should I keep the terminal open always? Because if the server stops, my web page wouldn't work. With Apache I just used commands apachectl start/stop.

  2. What if I want to use a command? Should I stop the server, use command, and run again? Because in the same terminal I can't do enything if the server run.

VVN
  • 1,607
  • 2
  • 16
  • 25
  • Well,you can start it in background or use some server like passenger, it's easy to use and convenient. – Andrey Saleba Aug 25 '16 at 04:12
  • How to start it in background? Like with Apache –  Aug 25 '16 at 04:31
  • 1
    To start rails server with apache as reverse proxy you need some application server to serve your ruby code. Check this link for guide how to set up it: https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html – Andrey Saleba Aug 25 '16 at 04:36
  • No, I use Puma server. I mean, how to run Puma in background, like we do it with apache –  Aug 25 '16 at 20:28

3 Answers3

30

you can run it in background by writing

daemonize true

in your puma.rb file

To stop you need to find your running puma process

 ps aux | grep puma

then you need to kill the main process

 sudo kill -9 your process id

to start you need to type

 puma -C config/puma.rb 
kajal ojha
  • 1,248
  • 8
  • 20
9

You can start a daemonized server by adding -d to your command. For instance:

rails server -d

To stop the server, you can kill it based on its process id:

kill $(cat tmp/pids/server.pid)
Flavio Wuensche
  • 9,460
  • 1
  • 57
  • 54
1

Should I keep the terminal open always? Because if the server stops, my web page wouldn't work. With Apache I just used commands apachectl start/stop.

Yes, you should keep it open because if you Ctrl C it will stop the server. Another option is to run it in the background but I'm not sure how to do that in Putty.

What if I want to use a command? Should I stop the server, use command, and run again? Because in the same terminal I can't do enything if the server run.

Can you open another terminal window? If you have two terminal windows you can use one for running the server and another for other tasks.

kcdragon
  • 1,724
  • 1
  • 14
  • 23
  • Ok, let's say you've developed a project and uploaded to a hosting. Where would you keep the terminal open? It seems stupid, why in apache is not like that? –  Aug 25 '16 at 04:23
  • Hosting in development and production are two very different scenarios. It usually easier to run in the terminal in development but you need something more robust for production. – kcdragon Aug 25 '16 at 04:47
  • What, for example? –  Aug 25 '16 at 20:28