unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Michael Guterl <mguterl@gmail.com>
To: unicorn list <mongrel-unicorn@rubyforge.org>
Subject: Re: Problem restarting Unicorn
Date: Thu, 5 Apr 2012 07:34:43 -0400	[thread overview]
Message-ID: <CAEn+1bcef4vZf18JmmiCNs_2=amACCiao8HUj3y4GQ3YOJZbAA@mail.gmail.com> (raw)
In-Reply-To: <1D1E83EF-886F-409D-B61E-22F7309C3690@airbladesoftware.com>

On Thu, Apr 5, 2012 at 3:21 AM, Andrew Stewart
<boss@airbladesoftware.com> wrote:
> Hello,
>
> I seem to be confused about how to restart Unicorn when deploying updates to a Rails app via Capistrano.
>
> I just had a problem where a bundled gem wasn't being seen by the Unicorn processes, even though app code I introduced at the same time was being served by the Unicorn processes.  I had restarted Unicorn numerous times using `bundle exec cap deploy:restart` (see the code below), which I thought was the right way to do zero-downtime restarts, but my problem was only solved by doing a hard restart of Unicorn with `bundle exec cap deploy:hard_restart`.
>
> With each "normal" restart I tailed the stderr log to check everything was ok; everything appeared fine, with gems refreshed etc.
>
> Please could somebody explain what I'm doing wrong with my normal restarts?
>
> config/deploy.rb:
>
>    set :unicorn_config, "#{current_path}/config/unicorn.rb"
>    set :unicorn_pid,    "#{shared_path}/pids/unicorn.pid"
>
>    namespace :deploy do
>      task :start, :roles => :app, :except => { :no_release => true } do
>        run "cd #{current_path} && #{sudo_workaround} bundle exec unicorn -c #{unicorn_config} -E #{rails_env} -D"
>      end
>      task :stop, :roles => :app, :except => { :no_release => true } do
>        run "#{sudo_workaround} kill -s QUIT `cat #{unicorn_pid}`"
>      end
>      task :hard_stop, :roles => :app, :except => { :no_release => true } do
>        run "#{sudo_workaround} kill `cat #{unicorn_pid}`"
>      end
>      task :restart, :roles => :app, :except => { :no_release => true } do
>        run "#{sudo_workaround} kill -s USR2 `cat #{unicorn_pid}`"
>      end
>      task :hard_restart, :roles => :app, :except => { :no_release => true } do
>        hard_stop
>        start
>      end
>    end
>
>    # Works around Ubuntu changing the PATH when you use sudo.
>    # sudo's path can find common commands like echo but not much else.
>    def sudo_workaround
>      "sudo env PATH=$PATH"
>    end
>
>
> config/unicorn.rb:
>
>    APP_PATH = '/var/www/apps/sparkle'
>    worker_processes 4
>    user 'rails', 'rails'
>    working_directory "#{APP_PATH}/current"
>    listen "/tmp/unicorn_sparkle.sock", :backlog => 64
>    timeout 30
>    pid "#{APP_PATH}/shared/pids/unicorn.pid"
>    stderr_path "#{APP_PATH}/shared/log/unicorn.stderr.log"
>    stdout_path "#{APP_PATH}/shared/log/unicorn.stdout.log"
>    preload_app true
>    GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true
>
>    before_fork do |server, worker|
>      defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
>
>      old_pid = "#{server.config[:pid]}.oldbin"
>      if old_pid != server.pid
>        begin
>          sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
>          Process.kill(sig, File.read(old_pid).to_i)
>        rescue Errno::ENOENT, Errno::ESRCH
>        end
>      end
>    end
>
>    after_fork do |server, worker|
>      defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
>    end
>
> This is all with Unicorn 4.2.0 and Rails 3.0.11.
>
> Many thanks in advance,
>

You probably want to check out the Sandbox documentation here:
http://unicorn.bogomips.org/Sandbox.html

The section that I think is most relevant is related to setting the START_CTX:

Unicorn::HttpServer::START_CTX[0] = "/some/path/to/bin/unicorn"

Hope that helps.

Best,
Michael Guterl
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

  reply	other threads:[~2012-04-05 11:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-05  7:21 Problem restarting Unicorn Andrew Stewart
2012-04-05 11:34 ` Michael Guterl [this message]
2012-04-10  8:52   ` Andrew Stewart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/unicorn/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEn+1bcef4vZf18JmmiCNs_2=amACCiao8HUj3y4GQ3YOJZbAA@mail.gmail.com' \
    --to=mguterl@gmail.com \
    --cc=mongrel-unicorn@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).