Sha256: ac54b5ef9646b6e9f9bd6b49eecbedc7f849c5a5e2a77f15430911f29d89b11c

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

require 'capistrano/unicorn_nginx/helpers'

include Capistrano::UnicornNginx::Helpers

namespace :load do
  task :defaults do
    set :unicorn_service_name, -> { "unicorn_#{fetch(:application)}_#{fetch(:stage)}" }
    set :templates_path, "config/deploy/templates"
    set :unicorn_pid, -> { shared_path.join("pids/unicorn.pid") }
    set :unicorn_config, -> { shared_path.join("config/unicorn.rb") }
    set :unicorn_log, -> { shared_path.join("log/unicorn.log") }
    set :unicorn_user, -> { fetch(:user) }
    set :unicorn_workers, 2
  end
end

namespace :unicorn do
  desc "Setup Unicorn initializer"
  task :setup_initializer do
    on roles(:app) do
      next if file_exists? "/etc/init.d/#{fetch(:unicorn_service_name)}"

      template "unicorn_init.erb", "/tmp/unicorn_init"
      execute :chmod, "+x", "/tmp/unicorn_init"
      sudo :mv, "/tmp/unicorn_init /etc/init.d/#{fetch(:unicorn_service_name)}"
      sudo "update-rc.d -f #{fetch(:unicorn_service_name)} defaults"
    end
  end

  desc "Setup Unicorn app configuration"
  task :setup_app_config do
    on roles(:app) do
      next if file_exists? fetch(:unicorn_config)

      execute :mkdir, "-p", shared_path.join("config")
      execute :mkdir, "-p", shared_path.join("log")
      execute :mkdir, "-p", shared_path.join("pids")
      template "unicorn.rb.erb", fetch(:unicorn_config)
    end
  end

  %w[start stop restart].each do |command|
    desc "#{command} unicorn"
    task command do
      on roles(:app) do
        execute "service #{fetch(:unicorn_service_name)} #{command}"
      end
    end
  end
end

namespace :deploy do
  after :updated, "unicorn:setup_initializer"
  after :updated, "unicorn:setup_app_config"
  after :publishing, "unicorn:restart"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capistrano-unicorn-nginx-0.0.1 lib/capistrano/tasks/unicorn.rake