rfc2822's blog

  • Archive
  • RSS
  • Contact me

How to restart god after deploying a Rails app with Capistrano

If you use the God gem to manage your Ruby on Rails application server (Unicorn, for example), you will have to restart the application server using God after deploying a new version.

I found a solution that polls the application’s tmp directory for restart.txt (like Phusion Passenger does) from within the god configuration and restarts the app if the file is touched. However, it didn’t work well for me because the ps syntax varies on different systems and the method is not very reliable (it triggered when I didn’t want it to, and vice versa).

So I thought about it and now I think that the best solution to restart an app via god is to do (surprise):

god restart YOUR-APP

And it should be done exactly if capistrano deploys, and not by polling.

To allow this command to be run by your deploying user, install sudo and make an entry into sudoers. It may look like this:

thedeployinguser ALL=(root) NOPASSWD: /usr/local/bin/god restart YourRailsServer

Then, all you need to do in config/deploy.rb is to make it look like this:

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
     run "ln -nfs #{shared_path}/sockets #{release_path}/tmp/sockets"
     sudo "god restart YourRailsServer"
  end
end

(I need the socket symlink for the Unicorn UNIX sockets.)

    • #rails
  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Recent comments

Blog comments powered by Disqus
← Previous • Next →

Logo

Pages

  • Author

Me, Elsewhere

  • rfc2822 on github

Following

  • staff
  • helmeloh
  • kaltspiegel
  • riverart
  • doki66
  • max-weller
  • oivoodoo
  • patrickonline
  • briilestinkt

I Dig These Posts

See more →
  • Photoset via huatunan

    色彩鹦鹉。color parrot
    Photoset via huatunan
  • Photo via androgynyous

    markrabadan:

    ASH STYMEST for OPEN LAB by MARK RABADAN.

    Photo via androgynyous
  • Photo via androgynyous
    Photo via androgynyous
  • Photo via kaltspiegel

    Bin bei meinen Eltern, hab bis Nachmittags gepennt und finde das in der Küche. Es sind die kleinen Dinge. <3

    Photo via kaltspiegel
  • Photo via riverart

    Looks like these guys turned my note 10.1 into a proper wireless wacom tablet.

    No lag, just fun. Check them out and donate if you like it :)

    Photo via riverart
  • RSS
  • Random
  • Archive
  • Contact me
  • Mobile

This content is licensed under the Creative Commons Attribute 3.0 Unported (CC BY 3.0) license.

Effector Theme by Pixel Union