Skip to content

Instantly share code, notes, and snippets.

@blackxored
Last active July 19, 2016 16:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save blackxored/7483765 to your computer and use it in GitHub Desktop.
Save blackxored/7483765 to your computer and use it in GitHub Desktop.
set :application, 'myapp'
set :repo_url, 'git@github.com:blackxored/myapp'
set :rails_env, 'production'
set :rbenv_type, :system
set :rbenv_ruby, "2.0.0-p247"
set :deploy_to, '/data/apps/myapp'
set :deploy_via, :remote_cache
set :user, 'deploy'
set :password, nil
set :group, "deploy"
set :unicorn_binary, "#{shared_path}/bin/unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid"
set :bundle_flags, "--deployment --quiet"
set :flowdock_project_name, "MyApp"
set :flowdock_deploy_tags, ENV['DEPLOY_TAGS'].to_s.split(",")
set :flowdock_api_token, "MY_TOKEN"
if ENV['BRANCH']
set :branch, ENV['BRANCH']
else
ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
end
set :format, :pretty
set :log_level, :info
set :linked_files, %w{config/mongoid.yml config/application.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
set :keep_releases, 5
no_release = ->(h) { h.properties.no_release }
namespace :deploy do
desc "Start application"
task :start do
on roles(:app), reject: no_release do
execute "cd #{current_path} && /usr/local/rbenv/shims/ruby #{fetch(:unicorn_binary)} -c #{fetch(:unicorn_config)} -E #{fetch(:rails_env, "production")} -D"
end
end
desc "Stop application"
task :stop do
on roles(:app), reject: no_release do
execute "kill `cat #{fetch(:unicorn_pid)}`"
end
end
desc "Gracefully stop application"
task :graceful_stop do
on roles(:app), reject: no_release do
execute "kill -s QUIT `cat #{fetch(:unicorn_pid)}`"
end
end
desc "Reload the application"
task :reload do
on roles(:app), reject: no_release do
execute "kill -s USR2 `cat #{fetch(:unicorn_pid)}`"
end
end
desc 'Restart application'
task :restart do
invoke 'deploy:stop'
invoke 'deploy:start'
end
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
after :finishing, 'deploy:cleanup'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment