Sha256: 79c8dd8d020e5b9a0760f19a0232f56e04dac302f8100f264a2e0d2e9e3d847a

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

namespace :load do
  task :defaults do
    set :unicorn_config, -> { File.join(current_path, 'config/unicorn.rb') }
    set :unicorn_pid,    -> { File.join(current_path, 'tmp/pids/unicorn.pid') }
    set :unicorn_roles,  -> { :app }
  end
end

namespace :unicorn do
  def start_unicorn
    within current_path do
      info 'Starting Unicorn ...'
      execute :bundle, :exec, :unicorn_rails, "-c #{fetch(:unicorn_config)} -E #{fetch(:rails_env)} -D"
    end
  end

  def stop_unicorn
    info 'Stopping Unicorn ...'
    execute :kill, "-s QUIT #{pid}"
  end

  def restart_unicorn
    info 'Restarting Unicorn ...'
    execute :kill, "-s USR2 #{pid}"
  end

  def remove_pid
    info 'Removing pid ...'
    execute :rm, fetch(:unicorn_pid)
  end

  def pid_exists?
    test("[ -e #{fetch(:unicorn_pid)} ]")
  end

  def pid_running?
    test("kill -0 #{pid}")
  end

  def pid
    "`cat #{fetch(:unicorn_pid)}`"
  end

  desc 'Start Unicorn'
  task :start do
    on roles(fetch(:unicorn_roles)) do
      if pid_exists? && pid_running?
        info 'Unicorn is running ...'
      else
        if pid_exists?
          remove_pid
        end

        start_unicorn
      end
    end
  end

  desc 'Stop Unicorn'
  task :stop do
    on roles(fetch(:unicorn_roles)) do
      if pid_exists?
        pid_running? ? stop_unicorn : remove_pid
      else
        info 'Unicorn is not running ...'
      end
    end
  end

  desc 'Restart Unicorn'
  task :restart do
    invoke 'unicorn:start'

    on roles(fetch(:unicorn_roles)) do
      restart_unicorn
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unicap-0.0.2 lib/unicap/tasks/unicap.rake