Skip to content

Instantly share code, notes, and snippets.

@itsNikolay
Created March 10, 2013 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsNikolay/5129912 to your computer and use it in GitHub Desktop.
Save itsNikolay/5129912 to your computer and use it in GitHub Desktop.
# coding: utf-8
require 'rvm/capistrano' # Для работы rvm
require "bundler/capistrano"
load 'deploy/assets'
server "198.211.125.210", :web, :app, :db, primary: true
set :application, "wood-awesome"
set :user, "user"
set :deploy_to, "/home/#{user}/projects/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "ssh://user@198.211.125.210:2912/home/#{user}/repos/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after 'deploy:restart', 'deploy:cleanup'
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_bin, 'unicorn'
set :unicorn_pid, "/tmp/#{application}.app.pid"
def remote_file_exists?(full_path)
capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip == 'true'
end
def process_exists?(pid_file)
capture("ps -p `cat #{pid_file}`; true").strip.split("\n").size == 2
end
namespace :deploy do
desc 'Start Unicorn'
task :start, roles: :app, except: {no_release: true} do
if remote_file_exists? unicorn_pid
if process_exists? unicorn_pid
logger.important 'Unicorn is already running!', 'Unicorn'
next
else
run "rm #{unicorn_pid}"
end
end
logger.important 'Starting Unicorn...', 'Unicorn'
run "cd #{current_path} && bundle exec unicorn -c #{unicorn_config} -E #{rails_env} -D"
end
desc 'Stop Unicorn'
task :stop, :roles => :app, :except => {:no_release => true} do
if remote_file_exists? unicorn_pid
if process_exists? unicorn_pid
logger.important 'Stopping Unicorn...', 'Unicorn'
run "kill -s QUIT `cat #{unicorn_pid}`"
else
run "rm #{unicorn_pid}"
logger.important 'Unicorn is not running.', 'Unicorn'
end
else
logger.important 'No PIDs found. Check if unicorn is running.', 'Unicorn'
end
end
desc 'Reload Unicorn'
task :reload, :roles => :app, :except => {:no_release => true} do
if remote_file_exists? unicorn_pid
logger.important 'Reloading Unicorn...', 'Unicorn'
run "kill -s HUP `cat #{unicorn_pid}`"
else
logger.important 'No PIDs found. Starting Unicorn...', 'Unicorn'
run "cd #{current_path} && bundle exec unicorn -c #{unicorn_config} -E #{rails_env} -D"
end
end
desc 'Restart Unicorn'
task :restart, :roles => :app, :except => {:no_release => true} do
stop
start
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment