caploy 0.2.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/caploy.gemspec +6 -12
- data/lib/caploy/railtie.rb +13 -0
- data/lib/caploy/recipes/assets.rb +11 -19
- data/lib/caploy/recipes/database.rb +44 -47
- data/lib/caploy/recipes/deploy.rb +219 -0
- data/lib/caploy/recipes/info.rb +24 -28
- data/lib/caploy/recipes/memcache.rb +9 -13
- data/lib/caploy/recipes/nginx.rb +82 -86
- data/lib/caploy/recipes/paperclip.rb +7 -8
- data/lib/caploy/recipes/seeding.rb +3 -5
- data/lib/caploy/recipes/setup.rb +31 -35
- data/lib/caploy/recipes/taillog.rb +22 -0
- data/lib/caploy/recipes/unicorn.rb +109 -108
- data/lib/caploy/templates/unicorn/unicorn.rb.erb +2 -2
- data/lib/caploy/version.rb +1 -1
- data/lib/caploy.rb +16 -1
- metadata +34 -153
- data/lib/caploy/recipes/airbrake.rb +0 -4
- data/lib/caploy/recipes/bundler.rb +0 -25
- data/lib/caploy/recipes/defaults.rb +0 -132
- data/lib/caploy/recipes/monitoring.rb +0 -12
- data/lib/caploy/recipes/passenger.rb +0 -32
- data/lib/caploy/recipes/puma.rb +0 -25
- data/lib/caploy/recipes/rbenv.rb +0 -7
- data/lib/caploy/recipes/redis.rb +0 -41
- data/lib/caploy/recipes/rvm.rb +0 -8
- data/lib/caploy/recipes/symlink.rb +0 -24
- data/lib/caploy/recipes/unicorn_bluepill.rb +0 -90
- data/lib/caploy/recipes/whenever.rb +0 -8
- data/lib/caploy/templates/bluepill/init.erb +0 -9
- data/lib/caploy/templates/bluepill/unicorn_config.rb.erb +0 -43
data/lib/caploy/recipes/nginx.rb
CHANGED
@@ -1,109 +1,105 @@
|
|
1
1
|
require "caploy/render"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
namespace :nginx do
|
6
|
-
desc <<-DESC
|
3
|
+
namespace :nginx do
|
4
|
+
desc <<-DESC
|
7
5
|
Starts the nginx web-server.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
DESC
|
7
|
+
task :start do
|
8
|
+
#run "sudo god start nginx"
|
9
|
+
run "sudo /etc/init.d/nginx start"
|
10
|
+
end
|
13
11
|
|
14
|
-
|
12
|
+
desc <<-DESC
|
15
13
|
#Stops the nginx web-server.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
DESC
|
15
|
+
task :stop do
|
16
|
+
#run "sudo god stop nginx"
|
17
|
+
run "sudo /etc/init.d/nginx stop"
|
18
|
+
end
|
21
19
|
|
22
|
-
|
20
|
+
desc <<-DESC
|
23
21
|
Restarts the nginx web-server.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
task :setup, :roles => :web do
|
31
|
-
protocol = fetch(:nginx_protocol, nil).to_s
|
32
|
-
template_path = File.expand_path('../../templates/nginx/vhost.erb', __FILE__)
|
33
|
-
vars = {
|
34
|
-
'application' => application,
|
35
|
-
'project_root' => deploy_to + '/current',
|
36
|
-
'domain' => vhost_domain, 'stage' => stage,
|
37
|
-
'auth_basic_title' => fetch(:auth_basic_title, nil),
|
38
|
-
'auth_basic_password_file' => fetch(:auth_basic_password_file, nil),
|
39
|
-
'protocol' => 'http',
|
40
|
-
'nginx_cert_dir' => fetch(:nginx_cert_dir, '/etc/nginx/cert'),
|
41
|
-
'with_upstream_server' => true,
|
42
|
-
'with_file_expire_max' => fetch(:with_file_expire_max, true),
|
43
|
-
'optional_http_content' => fetch(:optional_nginx_server_http_content, ''),
|
44
|
-
'optional_https_content' => fetch(:optional_nginx_server_https_content, ''),
|
45
|
-
'optional_nginx_http_content' => fetch(:optional_nginx_http_content, ''),
|
46
|
-
'optional_nginx_https_content' => fetch(:optional_nginx_https_content, ''),
|
47
|
-
'cert_type' => fetch(:cert_type, 'pem'),
|
48
|
-
'key_type' => fetch(:cert_type, 'key'),
|
49
|
-
'serve_static_files' => fetch(:nginx_serve_static_files, true),
|
50
|
-
'new_relic_support' => fetch(:nginx_new_relic_support, false)
|
51
|
-
}
|
52
|
-
|
53
|
-
sites_path = fetch(:nginx_sites_enabled_path, "/etc/nginx/sites-enabled")
|
54
|
-
|
55
|
-
if protocol.nil? or protocol == 'http' or protocol == 'both'
|
56
|
-
config_path = "#{shared_path}/config/#{application}_vhost.conf"
|
57
|
-
|
58
|
-
put(render_erb_template(template_path, vars), config_path)
|
59
|
-
|
60
|
-
with_user(fetch(:setup_user, user)) do
|
61
|
-
try_sudo "rm -f #{sites_path}/#{application}_#{stage}.conf"
|
62
|
-
try_sudo "ln -s #{config_path} #{sites_path}/#{application}_#{stage}.conf"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
if protocol == 'https' or protocol == 'both'
|
66
|
-
vars.merge!({'protocol' => 'https'})
|
67
|
-
|
68
|
-
config_path = "#{shared_path}/config/#{application}_ssl_vhost.conf"
|
22
|
+
DESC
|
23
|
+
task :restart do
|
24
|
+
#run "sudo god restart nginx"
|
25
|
+
run "sudo /etc/init.d/nginx restart"
|
26
|
+
end
|
69
27
|
|
70
|
-
|
28
|
+
task :setup, :roles => :web do
|
29
|
+
protocol = fetch(:nginx_protocol, nil).to_s
|
30
|
+
template_path = File.expand_path('../../templates/nginx/vhost.erb', __FILE__)
|
31
|
+
vars = {
|
32
|
+
'application' => application,
|
33
|
+
'project_root' => deploy_to + '/current',
|
34
|
+
'domain' => vhost_domain, 'stage' => stage,
|
35
|
+
'auth_basic_title' => fetch(:auth_basic_title, nil),
|
36
|
+
'auth_basic_password_file' => fetch(:auth_basic_password_file, nil),
|
37
|
+
'protocol' => 'http',
|
38
|
+
'nginx_cert_dir' => fetch(:nginx_cert_dir, '/etc/nginx/cert'),
|
39
|
+
'with_upstream_server' => true,
|
40
|
+
'with_file_expire_max' => fetch(:with_file_expire_max, true),
|
41
|
+
'optional_http_content' => fetch(:optional_nginx_server_http_content, ''),
|
42
|
+
'optional_https_content' => fetch(:optional_nginx_server_https_content, ''),
|
43
|
+
'optional_nginx_http_content' => fetch(:optional_nginx_http_content, ''),
|
44
|
+
'optional_nginx_https_content' => fetch(:optional_nginx_https_content, ''),
|
45
|
+
'cert_type' => fetch(:cert_type, 'pem'),
|
46
|
+
'key_type' => fetch(:cert_type, 'key'),
|
47
|
+
'serve_static_files' => fetch(:nginx_serve_static_files, true),
|
48
|
+
'new_relic_support' => fetch(:nginx_new_relic_support, false)
|
49
|
+
}
|
50
|
+
|
51
|
+
sites_path = fetch(:nginx_sites_enabled_path, "/etc/nginx/sites-enabled")
|
52
|
+
|
53
|
+
if protocol.nil? or protocol == 'http' or protocol == 'both'
|
54
|
+
config_path = "#{shared_path}/config/#{application}_vhost.conf"
|
55
|
+
|
56
|
+
put(render_erb_template(template_path, vars), config_path)
|
71
57
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
58
|
+
with_user(fetch(:setup_user, user)) do
|
59
|
+
try_sudo "rm -f #{sites_path}/#{application}_#{stage}.conf"
|
60
|
+
try_sudo "ln -s #{config_path} #{sites_path}/#{application}_#{stage}.conf"
|
76
61
|
end
|
77
62
|
end
|
63
|
+
if protocol == 'https' or protocol == 'both'
|
64
|
+
vars.merge!({ 'protocol' => 'https' })
|
65
|
+
|
66
|
+
config_path = "#{shared_path}/config/#{application}_ssl_vhost.conf"
|
78
67
|
|
79
|
-
|
80
|
-
protocol = fetch(:nginx_protocol, nil)
|
81
|
-
sites_path = fetch(:nginx_sites_enabled_path, "/etc/nginx/sites-enabled")
|
68
|
+
put(render_erb_template(template_path, vars), config_path)
|
82
69
|
|
83
70
|
with_user(fetch(:setup_user, user)) do
|
84
|
-
|
85
|
-
|
86
|
-
elsif protocol == 'https' or protocol == 'both'
|
87
|
-
try_sudo "rm -f #{sites_path}/#{application}_#{stage}_ssl.conf"
|
88
|
-
end
|
71
|
+
try_sudo "rm -f #{sites_path}/#{application}_#{stage}_ssl.conf"
|
72
|
+
try_sudo "ln -s #{config_path} #{sites_path}/#{application}_#{stage}_ssl.conf"
|
89
73
|
end
|
90
74
|
end
|
91
75
|
end
|
92
76
|
|
93
|
-
|
77
|
+
task :uninstall do
|
78
|
+
protocol = fetch(:nginx_protocol, nil)
|
79
|
+
sites_path = fetch(:nginx_sites_enabled_path, "/etc/nginx/sites-enabled")
|
94
80
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
81
|
+
with_user(fetch(:setup_user, user)) do
|
82
|
+
if protocol.blank? or protocol == 'http' or protocol == 'both'
|
83
|
+
try_sudo "rm -f #{sites_path}/#{application}_#{stage}.conf"
|
84
|
+
elsif protocol == 'https' or protocol == 'both'
|
85
|
+
try_sudo "rm -f #{sites_path}/#{application}_#{stage}_ssl.conf"
|
86
|
+
end
|
87
|
+
end
|
102
88
|
end
|
89
|
+
end
|
103
90
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
91
|
+
after :"deploy:setup", :"nginx:setup";
|
92
|
+
|
93
|
+
def with_user(new_user, &block)
|
94
|
+
old_user = user
|
95
|
+
set :user, new_user
|
96
|
+
close_sessions
|
97
|
+
yield
|
98
|
+
set :user, old_user
|
99
|
+
close_sessions
|
100
|
+
end
|
108
101
|
|
102
|
+
def close_sessions
|
103
|
+
sessions.values.each { |session| session.close }
|
104
|
+
sessions.clear
|
109
105
|
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
run "cd #{release_path}; RAILS_ENV=#{rails_env} #{rake} paperclip:refresh:missing_styles"
|
1
|
+
namespace :deploy do
|
2
|
+
desc 'build missing paperclip styles'
|
3
|
+
task :build_missing_paperclip_styles do
|
4
|
+
on roles(:app) do
|
5
|
+
execute "cd #{current_path}; RAILS_ENV=production bundle exec rake paperclip:refresh:missing_styles"
|
7
6
|
end
|
8
7
|
end
|
9
|
-
|
10
|
-
#after("deploy:update_code", "deploy:build_missing_paperclip_styles")
|
11
8
|
end
|
9
|
+
|
10
|
+
after('deploy:compile_assets', 'deploy:build_missing_paperclip_styles')
|
data/lib/caploy/recipes/setup.rb
CHANGED
@@ -1,48 +1,44 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end if defined?(config_file_to_setup)
|
11
|
-
end
|
1
|
+
namespace :deploy do
|
2
|
+
namespace :prepare do
|
3
|
+
task :create_config_files, :roles => :app do
|
4
|
+
run "mkdir -p #{shared_path}/config/"
|
5
|
+
config_file_to_setup.each do |config_file|
|
6
|
+
local_path = config_file_path(config_file)
|
7
|
+
put(File.read(local_path), "#{shared_path}/config/#{config_file}", :via => :scp) if local_path
|
8
|
+
end if defined?(config_file_to_setup)
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
desc "Set up shared directory structure"
|
12
|
+
task :create_shared_folders, :roles => :app do
|
13
|
+
directories_to_create.each { |directory| run "mkdir -p #{directory}" } if defined?(directories_to_create)
|
14
|
+
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
task :set_permissions, :roles => :app do
|
17
|
+
try_sudo "chown -R #{user}:#{fetch(:group, user)} #{deploy_to}" if fetch(:use_sudo, false)
|
18
|
+
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
task :database, :roles => :db do
|
21
|
+
_cset :db_admin_user, 'root'
|
22
|
+
_cset :db_admin_password, Capistrano::CLI.password_prompt("\e[0;31mType your mysql password for user '#{db_admin_user}' (not set if empty and ENTER): ")
|
23
|
+
_cset :db_name, application.gsub(/\W+/, '')[0..5] + '_' + rails_env.to_s
|
24
|
+
_cset :db_user_name, application
|
25
|
+
_cset :db_user_password, ''
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
setup_database_permissions
|
27
|
+
unless db_admin_password.to_s.empty?
|
28
|
+
unless database_exits?
|
29
|
+
create_database
|
34
30
|
end
|
31
|
+
setup_database_permissions
|
35
32
|
end
|
36
33
|
end
|
37
34
|
end
|
38
|
-
|
39
|
-
before 'deploy:setup', 'deploy:prepare:database';
|
40
|
-
before :'deploy:setup', :'deploy:prepare:create_config_files';
|
41
|
-
before :'deploy:setup', :'deploy:prepare:create_shared_folders';
|
42
|
-
after 'deploy:setup', 'deploy:prepare:set_permissions';
|
43
|
-
|
44
35
|
end
|
45
36
|
|
37
|
+
before 'deploy:setup', 'deploy:prepare:database';
|
38
|
+
before :'deploy:setup', :'deploy:prepare:create_config_files';
|
39
|
+
before :'deploy:setup', :'deploy:prepare:create_shared_folders';
|
40
|
+
after 'deploy:setup', 'deploy:prepare:set_permissions';
|
41
|
+
|
46
42
|
def config_file_path(config_file_name)
|
47
43
|
config_file = "#{rails_root}/config/#{config_file_name}"
|
48
44
|
if File.exists? config_file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
desc 'Tail application log'
|
2
|
+
task :tail_logs do
|
3
|
+
on roles (:app) do
|
4
|
+
tail "#{shared_path}/log/#{fetch(:rails_env)}.log"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def with_verbosity(output_verbosity)
|
9
|
+
old_verbosity = SSHKit.config.output_verbosity
|
10
|
+
begin
|
11
|
+
SSHKit.config.output_verbosity = output_verbosity
|
12
|
+
yield
|
13
|
+
ensure
|
14
|
+
SSHKit.config.output_verbosity = old_verbosity
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def tail(path)
|
19
|
+
with_verbosity(Logger::DEBUG) do
|
20
|
+
execute "tail -f #{path}"
|
21
|
+
end
|
22
|
+
end
|
@@ -1,136 +1,137 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
|
7
|
-
end
|
8
|
-
|
9
|
-
# Check if process is running
|
10
|
-
#
|
11
|
-
def process_exists?(pid_file)
|
12
|
-
capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2
|
13
|
-
end
|
1
|
+
# Check if remote file exists
|
2
|
+
#
|
3
|
+
def remote_file_exists?(full_path)
|
4
|
+
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
|
5
|
+
end
|
14
6
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
_cset (:unicorn_env) { app_env }
|
21
|
-
_cset (:unicorn_std_log) { "log/unicorn.stderr.log" }
|
22
|
-
_cset (:unicorn_err_log) { "log/unicorn.stderr.log" }
|
23
|
-
_cset (:unicorn_worker_processes) { 2 }
|
24
|
-
_cset (:unicorn_timeout) { 30 }
|
25
|
-
_cset (:unicorn_listen_backlog) { 2048 }
|
26
|
-
_cset (:sidekiq_redis_url) { nil }
|
27
|
-
_cset (:sidekiq_redis_count) { 1 }
|
28
|
-
_cset (:unicorn_hard_restart) { false }
|
7
|
+
# Check if process is running
|
8
|
+
#
|
9
|
+
def process_exists?(pid_file)
|
10
|
+
capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2
|
11
|
+
end
|
29
12
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
13
|
+
# Set unicorn vars
|
14
|
+
#
|
15
|
+
_cset (:app_env) { fetch(:rails_env, 'production') }
|
16
|
+
_cset (:unicorn_bin) { "unicorn" }
|
17
|
+
_cset (:unicorn_pid) { "#{fetch(:current_path)}/tmp/pids/unicorn.pid" }
|
18
|
+
_cset (:unicorn_env) { app_env }
|
19
|
+
_cset (:unicorn_std_log) { "log/unicorn.stderr.log" }
|
20
|
+
_cset (:unicorn_err_log) { "log/unicorn.stderr.log" }
|
21
|
+
_cset (:unicorn_worker_count) { 2 }
|
22
|
+
_cset (:unicorn_timeout) { 30 }
|
23
|
+
_cset (:unicorn_listen_backlog) { 2048 }
|
24
|
+
_cset (:sidekiq_redis_url) { nil }
|
25
|
+
_cset (:sidekiq_redis_count) { 1 }
|
26
|
+
_cset (:unicorn_hard_restart) { false }
|
41
27
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
28
|
+
namespace :unicorn do
|
29
|
+
desc 'Start Unicorn'
|
30
|
+
task :start, :roles => :app, :except => { :no_release => true } do
|
31
|
+
if remote_file_exists?(unicorn_pid)
|
32
|
+
if process_exists?(unicorn_pid)
|
33
|
+
logger.important("Unicorn is already running!", "Unicorn")
|
34
|
+
next
|
46
35
|
else
|
47
|
-
|
36
|
+
run "rm #{unicorn_pid}"
|
48
37
|
end
|
49
38
|
end
|
50
39
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
else
|
58
|
-
run "rm #{unicorn_pid}"
|
59
|
-
logger.important("Unicorn is not running.", "Unicorn")
|
60
|
-
end
|
61
|
-
else
|
62
|
-
logger.important("No PIDs found. Check if unicorn is running.", "Unicorn")
|
63
|
-
end
|
40
|
+
config_path = "#{current_path}/config/unicorn/#{unicorn_env}.rb"
|
41
|
+
if remote_file_exists?(config_path)
|
42
|
+
logger.important("Starting...", "Unicorn - #{bundle_cmd} ")
|
43
|
+
run "cd #{current_path} && #{bundle_cmd} exec #{unicorn_bin} -c #{config_path} -E #{app_env} -D"
|
44
|
+
else
|
45
|
+
logger.important("Config file for \"#{unicorn_env}\" environment was not found at \"#{config_path}\"", "Unicorn")
|
64
46
|
end
|
47
|
+
end
|
65
48
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
else
|
73
|
-
run "rm #{unicorn_pid}"
|
74
|
-
logger.important("Unicorn is not running.", "Unicorn")
|
75
|
-
end
|
49
|
+
desc 'Stop Unicorn'
|
50
|
+
task :stop, :roles => :app, :except => { :no_release => true } do
|
51
|
+
if remote_file_exists?(unicorn_pid)
|
52
|
+
if process_exists?(unicorn_pid)
|
53
|
+
logger.important("Stopping...", "Unicorn")
|
54
|
+
run "#{try_sudo} kill `cat #{unicorn_pid}`"
|
76
55
|
else
|
77
|
-
|
56
|
+
run "rm #{unicorn_pid}"
|
57
|
+
logger.important("Unicorn is not running.", "Unicorn")
|
78
58
|
end
|
59
|
+
else
|
60
|
+
logger.important("No PIDs found. Check if unicorn is running.", "Unicorn")
|
79
61
|
end
|
62
|
+
end
|
80
63
|
|
81
|
-
|
82
|
-
|
83
|
-
|
64
|
+
desc 'Unicorn graceful shutdown'
|
65
|
+
task :graceful_stop, :roles => :app, :except => { :no_release => true } do
|
66
|
+
if remote_file_exists?(unicorn_pid)
|
67
|
+
if process_exists?(unicorn_pid)
|
84
68
|
logger.important("Stopping...", "Unicorn")
|
85
|
-
|
86
|
-
unicorn.stop
|
87
|
-
sleep(2)
|
88
|
-
unicorn.start
|
89
|
-
else
|
90
|
-
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
|
91
|
-
end
|
69
|
+
run "#{try_sudo} kill -s QUIT `cat #{unicorn_pid}`"
|
92
70
|
else
|
93
|
-
|
94
|
-
|
95
|
-
if remote_file_exists?(config_path)
|
96
|
-
run "cd #{current_path} && #{bundle_cmd} exec #{unicorn_bin} -c #{config_path} -E #{app_env} -D"
|
97
|
-
else
|
98
|
-
logger.important("Config file for \"#{unicorn_env}\" environment was not found at \"#{config_path}\"", "Unicorn")
|
99
|
-
end
|
71
|
+
run "rm #{unicorn_pid}"
|
72
|
+
logger.important("Unicorn is not running.", "Unicorn")
|
100
73
|
end
|
74
|
+
else
|
75
|
+
logger.important("No PIDs found. Check if unicorn is running.", "Unicorn")
|
101
76
|
end
|
77
|
+
end
|
102
78
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
79
|
+
desc 'Reload Unicorn'
|
80
|
+
task :reload, :roles => :app, :except => { :no_release => true } do
|
81
|
+
if remote_file_exists?(unicorn_pid)
|
82
|
+
logger.important("Stopping...", "Unicorn")
|
83
|
+
if unicorn_hard_restart
|
84
|
+
unicorn.stop
|
85
|
+
sleep(2)
|
86
|
+
unicorn.start
|
87
|
+
else
|
88
|
+
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
|
89
|
+
end
|
90
|
+
else
|
91
|
+
logger.important("No PIDs found. Starting Unicorn server...", "Unicorn")
|
92
|
+
config_path = "#{current_path}/config/unicorn/#{unicorn_env}.rb"
|
93
|
+
if remote_file_exists?(config_path)
|
94
|
+
run "cd #{current_path} && #{bundle_cmd} exec #{unicorn_bin} -c #{config_path} -E #{app_env} -D"
|
95
|
+
else
|
96
|
+
logger.important("Config file for \"#{unicorn_env}\" environment was not found at \"#{config_path}\"", "Unicorn")
|
97
|
+
end
|
122
98
|
end
|
123
99
|
end
|
124
100
|
|
125
|
-
|
126
|
-
|
101
|
+
desc "Setup unicorn"
|
102
|
+
task :setup, :roles => :app, :except => { :no_release => true } do
|
103
|
+
run "mkdir -p \"#{shared_path}/config/unicorn\""
|
104
|
+
config_path = "#{shared_path}/config/unicorn/#{rails_env}.rb"
|
105
|
+
template_path = File.expand_path('../../templates/unicorn/unicorn.rb.erb', __FILE__)
|
106
|
+
vars = {
|
107
|
+
'application' => application,
|
108
|
+
'current_path' => current_path,
|
109
|
+
'unicorn_pid' => unicorn_pid,
|
110
|
+
'unicorn_std_log' => unicorn_std_log,
|
111
|
+
'unicorn_err_log' => unicorn_err_log,
|
112
|
+
'stage' => stage,
|
113
|
+
'unicorn_listen_backlog' => unicorn_listen_backlog,
|
114
|
+
'unicorn_worker_count' => unicorn_worker_count,
|
115
|
+
'unicorn_timeout' => unicorn_timeout,
|
116
|
+
'sidekiq_redis_count' => sidekiq_redis_count,
|
117
|
+
'sidekiq_redis_url' => sidekiq_redis_url
|
118
|
+
}
|
119
|
+
put(render_erb_template(template_path, vars), config_path)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
after :"deploy:restart", :"unicorn:reload"
|
124
|
+
after :"deploy:setup", :"unicorn:setup";
|
127
125
|
|
128
|
-
|
129
|
-
|
126
|
+
namespace :deploy do
|
127
|
+
task :start do
|
128
|
+
on roles(:app) do
|
130
129
|
unicorn.start
|
131
130
|
end
|
131
|
+
end
|
132
132
|
|
133
|
-
|
133
|
+
task :stop do
|
134
|
+
on roles(:app) do
|
134
135
|
unicorn.stop
|
135
136
|
end
|
136
137
|
end
|
@@ -4,7 +4,7 @@ stderr_path "<%= unicorn_std_log %>"
|
|
4
4
|
stdout_path "<%= unicorn_err_log %>"
|
5
5
|
|
6
6
|
listen "/tmp/socket.<%= application %>_<%= stage %>.sock", :backlog => <%= unicorn_listen_backlog %>
|
7
|
-
worker_processes <%=
|
7
|
+
worker_processes <%= unicorn_worker_count %>
|
8
8
|
timeout <%= unicorn_timeout %>
|
9
9
|
|
10
10
|
preload_app true
|
@@ -45,4 +45,4 @@ after_fork do |server, worker|
|
|
45
45
|
<% end %>
|
46
46
|
end
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|
data/lib/caploy/version.rb
CHANGED
data/lib/caploy.rb
CHANGED
@@ -1 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require 'caploy/version'
|
2
|
+
|
3
|
+
module Caploy
|
4
|
+
require 'caploy/railtie' if defined?(Rails)
|
5
|
+
|
6
|
+
# Load DSL and Setup Up Stages
|
7
|
+
require 'capistrano/setup'
|
8
|
+
|
9
|
+
# Includes default deployment tasks
|
10
|
+
require 'capistrano/deploy'
|
11
|
+
|
12
|
+
# Includes tasks from other gems included in your Gemfile
|
13
|
+
require 'capistrano/rails'
|
14
|
+
require 'capistrano/rbenv'
|
15
|
+
require 'capistrano3/unicorn'
|
16
|
+
end
|