Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7413645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:56:22+00:00 2026-05-29T06:56:22+00:00

my head hurts today! :) I need some help with rails deployment. I migrated

  • 0

my head hurts today! 🙂

I need some help with rails deployment.

I migrated from cherokee to nginx and well, I migrated my django apps easily.

I just have to launch uwsgi to get a tcp socket and run my app. So I use supervisord to start / stop uwsgi sockets for every app.

I want something similar for rails. I just started with rails but I want to be able to deploy now so I won’t have problems in a future.

I read all almost all internet and well, I have to ask here 🙂

My app lives in “/srv/http/hello/”

I use unicorn with a fancy config/unicorn.rb

worker_processes 2
working_directory "/srv/http/hello/"

# This loads the application in the master process before forking
# worker processes
# Read more about it here:
# http://unicorn.bogomips.org/Unicorn/Configurator.html
preload_app true

timeout 30

# This is where we specify the socket.
# We will point the upstream Nginx module to this socket later on
listen "/srv/http/hello/tmp/sockets/unicorn.sock", :backlog => 64

pid "/srv/http/hello/tmp/pids/unicorn.pid"

# Set the path of the log files inside the log folder of the testapp
stderr_path "/var/log/unicorn/hello-stderr.log"
stdout_path "/var/log/unicorn/hello-stdout.log"

before_fork do |server, worker|
# This option works in together with preload_app true setting
# What is does is prevent the master process from holding
# the database connection
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
# Here we are establishing the connection after forking worker
# processes
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

I just adapted some example for internet.

If I run something like:

unicorn_rails -c config/unicorn.rb -D

It works like a charm. I tried to put that command in supervisord but hehe, I asked too much for it.

So, with some research I discovered god, so I picked the example of github and I put it on “config/god.rb” (which is the good place?)

# http://unicorn.bogomips.org/SIGNALS.html

rails_env = ENV['RAILS_ENV'] || 'development'
rails_root = ENV['RAILS_ROOT'] || "/srv/http/hello"

God.watch do |w|
  w.name = "unicorn"
  w.interval = 30.seconds # default

  # unicorn needs to be run from the rails root
  w.start = "cd #{rails_root} && /srv/http/.rvm/gems/ruby-1.9.3-p0@hello/bin/unicorn_rails -c #{rails_root}/config/unicorn.rb -E #{rails_env} -D"

  # QUIT gracefully shuts down workers
  w.stop = "kill -QUIT `cat #{rails_root}/tmp/pids/unicorn.pid`"

  # USR2 causes the master to re-create itself and spawn a new worker pool
  w.restart = "kill -USR2 `cat #{rails_root}/tmp/pids/unicorn.pid`"

  w.start_grace = 10.seconds
  w.restart_grace = 10.seconds
  w.pid_file = "#{rails_root}/tmp/pids/unicorn.pid"

  #w.uid = 'http'
  #w.gid = 'webgroup'

  w.behavior(:clean_pid_file)

  w.start_if do |start|
    start.condition(:process_running) do |c|
      c.interval = 5.seconds
      c.running = false
    end
  end

  w.restart_if do |restart|
    restart.condition(:memory_usage) do |c|
      c.above = 300.megabytes
      c.times = [3, 5] # 3 out of 5 intervals
    end

    restart.condition(:cpu_usage) do |c|
      c.above = 50.percent
      c.times = 5
    end
  end

  # lifecycle
  w.lifecycle do |on|
    on.condition(:flapping) do |c|
      c.to_state = [:start, :restart]
      c.times = 5
      c.within = 5.minute
      c.transition = :unmonitored
      c.retry_in = 10.minutes
      c.retry_times = 5
      c.retry_within = 2.hours
    end
  end
end

NOTE: I commented the uid and gid since I launch it from the http user or I get a permission error writing the pid. Also I put “development” because is just a “rails new hello”

Ok, so this works:

god -c config/god.rb -D

god launch unicorn good and in another terminal and I can do “god stop unicorn” and it works.

So questions…

1 – Is this the correct way?
2 – Do I need one god config for every project and launch a god process for every project?
3 – How can I manage those god’s process? Something like supervisord “supervisorctl restart djangoproject”
4 – Will I die if I put “killall god” 3 times in a row? 😛
5 – NEW QUESTION: Im too far if I say that I just need 1 god config with ALL unicorn instances, launch it in some form and just manage it with god? god start blah, god start bleh…

Thanks a lot, I just need to start rails development with a good system administration.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:56:23+00:00Added an answer on May 29, 2026 at 6:56 am

    If you already have experience with uWSGI why not using it for rails too ?

    http://projects.unbit.it/uwsgi/wiki/RubyOnRails

    If you plan to host a lot of apps consider using the Emperor

    http://projects.unbit.it/uwsgi/wiki/Emperor

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, my head hurts...! This beautiful MySQL query: (SELECT mtwitterfollowers AS twitfollow FROM `media`
My head hurts so much I think I need a bottle of aspirin... I've
i have tried till my head hurts and have been reading so much my
My head is about to explode with this logic, can anyone help? Class A
I'm pretty sure regular expressions are the way to go, but my head hurts
I'm trying to read an RSS feed from Flickr but it has some nodes
Head First book says about include directive as include code from any other file
If my title hurts your head... I'm with you. I don't want to get
I had a head-scratcher yesterday. Basically I had an associative array of some data
I really don't understand regex at all, and it hurts my head. I've a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.