31

I'm following the instructions here http://railsinstaller.org/mac to get up and running with Rails on a Mac running OS X 10.8.2

At step 8 I'm asked to restart Rails server but how?

I'm assuming via a command line, but from within the already open ruby terminal window or a new one?

jefflunt
  • 32,075
  • 7
  • 80
  • 122
Paul Seattle
  • 461
  • 1
  • 5
  • 10

6 Answers6

40

Press Ctrl+C

When you start the server it mentions this in the startup text.

jefflunt
  • 32,075
  • 7
  • 80
  • 122
35

Now in rails 5 yu can do:

rails restart

This print by rails --tasks

Restart app by touching tmp/restart.txt

I think that is usefully if you run rails as a demon

26

On OSX, you can take advantage of the UNIX-like command line - here's what I keep handy in my .bashrc to enable me to more easily restart a server that's running in background (-d) mode (note that you have to be in the Rails root directory when running this):

alias restart_rails='kill -9 `cat tmp/pids/server.pid`; rails server -d'

My initial response to the comment by @zane about how the PID file isn't removed was that it might be behavior dependent on the Rails version or OS type. However, it's also possible that the shell runs the second command (rails server -d) sooner than the kill can actually cause the previous running instance to stop.

So alternatively, kill -9 cat tmp/pids/server.pid && rails server -d might be more robust; or you can specifically run the kill, wait for the tmp/pids folder to empty out, then restart your new server.

sameers
  • 4,447
  • 2
  • 28
  • 42
  • 2
    Using kill -9 leaves the pid file on my system, meaning that starting the server again will result in a "server already running" error (and the server will not start again). Use kill with out "-9", this will remove the pid file. – Zane Feb 08 '15 at 00:51
  • @Zane - you might want to say something about your Rails and OS versions. On OSX 10.8, with Rails 4+, an "orphaned" PID file caused due to `kill -9`, aka, `SIGKILL`, does _not_ cause the "Server already running" message to be output. – sameers Feb 09 '15 at 01:24
  • sameers: good point, and interesting that behavior is different. OS: Linux manjaro 3.16.7.4-1-MANJARO Rails: 4.2.0. – Zane Feb 10 '15 at 11:23
  • This results in `Broken pipe (Errno::EPIPE)` when the server restarts for me. – Qwertie Jun 24 '19 at 01:00
  • @Qwertie you will have to say more - I can't reproduce on Rails5.2.2; OSX Mojave – sameers Jun 25 '19 at 04:33
  • I was testing on fedora 29, it might work differently. – Qwertie Jun 25 '19 at 05:05
1

In case that doesn't work there is another way that works especially well in Windows: Kill localhost:3000 process from Windows command line

Community
  • 1
  • 1
0

I had to restart the rails application on the production so I looked for an another answer. I have found it below:

http://wiki.ocssolutions.com/Restarting_a_Rails_Application_Using_Passenger

Nickolay Kondratenko
  • 1,644
  • 1
  • 19
  • 24
0

if you are not able to find the rails process to kill it might actually be not running. Delete the tmp folder and its sub-folders from where you are running the rails server and try again.

Rohan
  • 411
  • 4
  • 3