Restarting a rails server started as daemon may be boring after some time, now I show you a fast and easy way to do it

I generally start rails server (WEBrick and Rails 3.2.11) as a daemon rails s -d , when I don’t need debugging. Restarting it is very boring, as you need to find the process with ps aux | grep rails  and kill it. Well this solution will not revolutionize your life, but is very useful. You need this two lines of shell script to restart the server

kill -9 `cat tmp/pids/server.pid`
rails s -d

And only the first line to stop it. The nice part is the tmp/pids/server.pid file which stores the process id!

You can create a function (or two) in your .bashrc

rails-restart() { 
  rails-stop() 
  rails s -d 
} 
rails-stop() { 
  kill -9 `cat tmp/pids/server.pid` 
}

and don’t forget to source it source ~/.bashrc after the modification, now you can call them simply as rails-restart (obviously work only from the rails app folder).

Please share your solutions!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>