-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththin_faye_deploy.rb
More file actions
82 lines (68 loc) · 2.32 KB
/
thin_faye_deploy.rb
File metadata and controls
82 lines (68 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require "bundler/capistrano"
require 'capistrano/ext/multistage'
set :stages, %w(production development staging)
set :default_stage, "development"
set :application, "thin_faye"
set :user, "deployer"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :ssh_options, { :forward_agent => true }
set :git_enable_submodules,1
set :scm, "git"
set :repository, "git@github.com:thinchat/#{application}.git"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
def current_git_branch
`git symbolic-ref HEAD`.gsub("refs/heads/", "")
end
def prompt_with_default(message, default)
response = Capistrano::CLI.ui.ask "#{message} Default is: [#{default}] : "
response.empty? ? default : response
end
def set_branch
if current_git_branch != "master"
set :branch, ENV['BRANCH'] || prompt_with_default("Enter branch to deploy, or ENTER for default.", "#{current_git_branch.chomp}")
else
set :branch, ENV['BRANCH'] || "#{current_git_branch.chomp}"
end
end
set :branch, set_branch
after "deploy", "deploy:start"
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} faye"
task command, roles: :app, except: {no_release: true} do
sudo "god load #{current_path}/config/god/faye_server.#{rails_env}.god"
sudo "service god-service #{command} thin_faye"
end
end
task :create_release_dir, :except => {:no_release => true} do
run "mkdir -p #{fetch :releases_path}"
end
before "deploy:update_code", "deploy:create_release_dir"
desc "Deploy to a server for the first time (assumes you've run 'cap stage-name provision')"
task :fresh, roles: :app do
puts "Deploying to fresh server..."
end
after "deploy:fresh", "deploy:setup", "deploy"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end
namespace :god do
desc "Status of god tasks"
task :status, roles: :app do
sudo "god status"
end
desc "Load god file"
task :load_config, roles: :app do
sudo "god load #{current_path}/config/god/#{application}.#{rails_env}.god"
end
end