H
H
helixly2015-04-22 22:27:07
Ruby on Rails
helixly, 2015-04-22 22:27:07

What is the correct way to restart Unicorn?

New to rails, please help. I start Unicorn with the command

unicorn_rails -c config/unicorn.rb -D -E development

The bottom line is, when changing the config or just if you want to change the environment, you need to kill the process and start it all over again. Is there a way to automate or simplify the restart somehow? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2015-04-23
@helixly

You can send a signal:
In my Capistrano I use it like this:

namespace :unicorn do
  pid_path = "#{release_path}/tmp/pids"
  unicorn_pid = "#{pid_path}/unicorn.pid"

  def run_unicorn
    execute "#{fetch(:bundle_binstubs)}/unicorn", "-c #{release_path}/config/unicorn.rb -D -E #{fetch(:stage)}"
  end

  desc 'Start unicorn'
  task :start do
    on roles(:app) do
      run_unicorn
    end
  end

  desc 'Stop unicorn'
  task :stop do
    on roles(:app) do
      if test "[ -f #{unicorn_pid} ]"
        execute :kill, "-QUIT `cat #{unicorn_pid}`"
      end
    end
  end

  desc 'Force stop unicorn (kill -9)'
  task :force_stop do
    on roles(:app) do
      if test "[ -f #{unicorn_pid} ]"
        execute :kill, "-9 `cat #{unicorn_pid}`"
        execute :rm, unicorn_pid
      end
    end
  end

  desc 'Restart unicorn'
  task :restart do
    on roles(:app) do
      if test "[ -f #{unicorn_pid} ]"
        execute :kill, "-USR2 `cat #{unicorn_pid}`"
      else
        run_unicorn
      end
    end
  end
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question