Skip to content

Instantly share code, notes, and snippets.

@tadyjp
Created February 2, 2016 01:11
Show Gist options
  • Select an option

  • Save tadyjp/7fd9f2b0b5d4297d2525 to your computer and use it in GitHub Desktop.

Select an option

Save tadyjp/7fd9f2b0b5d4297d2525 to your computer and use it in GitHub Desktop.

Revisions

  1. tadyjp created this gist Feb 2, 2016.
    30 changes: 30 additions & 0 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    namespace :unicorn do
    desc 'Force restart Unicorn (sequential)'
    task :force_restart do
    on roles(fetch(:unicorn_roles)), in: :sequence, wait: 10 do
    within current_path do
    if test("[ -e #{fetch(:unicorn_pid)} ]")
    if test("kill -0 #{pid}")
    info 'stopping unicorn...'
    execute :kill, '-s QUIT', pid
    else
    info 'cleaning up dead unicorn pid...'
    execute :rm, fetch(:unicorn_pid)
    end

    sleep(3)

    if test("[ -e #{fetch(:unicorn_pid)} ] && kill -0 #{pid}")
    info 'unicorn is running...'
    else
    with rails_env: fetch(:rails_env) do
    execute :bundle, 'exec unicorn', '-c', fetch(:unicorn_config_path), '-E', fetch(:unicorn_rack_env), '-D', fetch(:unicorn_options)
    end
    end
    else
    info 'unicorn is not running...'
    end
    end
    end
    end
    end