capper 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/capper.gemspec +1 -1
- data/lib/capper/base.rb +5 -2
- data/lib/capper/delayed_job.rb +38 -0
- data/lib/capper/monit.rb +8 -6
- data/lib/capper/templates/delayed_job.sh.erb +19 -0
- data/lib/capper/unicorn.rb +12 -10
- data/lib/capper/utils/monit.rb +4 -2
- data/lib/capper/utils/templates.rb +7 -28
- metadata +11 -9
data/capper.gemspec
CHANGED
data/lib/capper/base.rb
CHANGED
@@ -45,11 +45,14 @@ Capper.load do
|
|
45
45
|
|
46
46
|
# default app layout
|
47
47
|
_cset(:user) { application }
|
48
|
-
|
48
|
+
|
49
49
|
_cset(:base_path) { "/var/app" }
|
50
|
-
_cset(:config_path) { "#{shared_path}/config" }
|
51
50
|
set(:deploy_to) { "#{base_path}/#{application}" }
|
52
51
|
|
52
|
+
_cset(:bin_path) { File.join(deploy_to, "bin") }
|
53
|
+
_cset(:pid_path) { File.join(shared_path, "pids") }
|
54
|
+
_cset(:config_path) { File.join(shared_path, "config") }
|
55
|
+
|
53
56
|
# set proper unicode locale, so gemspecs with unicode chars will not crash
|
54
57
|
# bundler. see https://github.com/capistrano/capistrano/issues/70
|
55
58
|
_cset(:default_environment, { 'LANG' => 'en_US.UTF-8' })
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/base' unless defined?(Capper)
|
2
|
+
|
3
|
+
require 'capper/bundler'
|
4
|
+
|
5
|
+
Capper.load do
|
6
|
+
# unicorn configuration variables
|
7
|
+
_cset(:delayed_job_workers, {})
|
8
|
+
|
9
|
+
# these cannot be overriden
|
10
|
+
set(:delayed_job_script) { File.join(bin_path, "delayed_job") }
|
11
|
+
|
12
|
+
monit_config "delayed_job", <<EOF, :roles => :worker
|
13
|
+
<% delayed_job_workers.each do |name, range| %>
|
14
|
+
check process delayed_job_<%= name %>
|
15
|
+
with pidfile <%= pid_path %>/delayed_job.<%= name %>.pid
|
16
|
+
<% if range.nil? %>
|
17
|
+
start program = "<%= delayed_job_script %> start <%= name %>"
|
18
|
+
stop program = "<%= delayed_job_script %> stop <%= name %>"
|
19
|
+
<% else %>
|
20
|
+
start program = "<%= delayed_job_script %> start <%= name %> <%= range.begin %> <%= range.end %>"
|
21
|
+
stop program = "<%= delayed_job_script %> stop <%= name %> <%= range.begin %> <%= range.end %>"
|
22
|
+
<% end %>
|
23
|
+
group delayed_job
|
24
|
+
|
25
|
+
<% end %>
|
26
|
+
EOF
|
27
|
+
|
28
|
+
namespace :delayed_job do
|
29
|
+
desc "Generate delayed_job configuration files"
|
30
|
+
task :setup, :except => { :no_release => true } do
|
31
|
+
upload_template_file("delayed_job.sh",
|
32
|
+
delayed_job_script,
|
33
|
+
:mode => "0755")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
after "deploy:update_code", "delayed_job:setup"
|
38
|
+
end
|
data/lib/capper/monit.rb
CHANGED
@@ -5,14 +5,16 @@ Capper.load do
|
|
5
5
|
|
6
6
|
namespace :monit do
|
7
7
|
task :setup do
|
8
|
-
configs =
|
8
|
+
configs = fetch(:monit_configs, {})
|
9
9
|
|
10
|
-
|
11
|
-
configs
|
10
|
+
upload_template(monitrc, :mode => "0644") do |server|
|
11
|
+
configs.keys.select do |name|
|
12
|
+
options = configs[name][:options]
|
13
|
+
find_servers(options).include?(server)
|
14
|
+
end.map do |name|
|
15
|
+
"# #{name}\n#{configs[name][:body]}"
|
16
|
+
end.join("\n\n")
|
12
17
|
end
|
13
|
-
|
14
|
-
upload_template_string(configs.join("\n\n"),
|
15
|
-
monitrc, :mode => "0644")
|
16
18
|
end
|
17
19
|
|
18
20
|
task :reload do
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
export HOME=<%= deploy_to %>
|
3
|
+
source <%= deploy_to %>/.rvm/scripts/rvm
|
4
|
+
export RAILS_ENV=<%= rails_env %>
|
5
|
+
|
6
|
+
cd <%= current_path %> >/dev/null
|
7
|
+
|
8
|
+
CMD=$1 && shift
|
9
|
+
ID=$1 && shift
|
10
|
+
|
11
|
+
if [[ $# -ge 1 ]]; then
|
12
|
+
MIN="--min-priority $1" && shift
|
13
|
+
fi
|
14
|
+
|
15
|
+
if [[ $# -ge 1 ]]; then
|
16
|
+
MAX="--max-priority $1" && shift
|
17
|
+
fi
|
18
|
+
|
19
|
+
exec bundle exec ./script/delayed_job $CMD --prefix <%= application %> --identifier $ID --pid-dir=<%= pid_path %> $MIN $MAX
|
data/lib/capper/unicorn.rb
CHANGED
@@ -12,15 +12,15 @@ Capper.load do
|
|
12
12
|
_cset(:unicorn_backlog, 64)
|
13
13
|
|
14
14
|
# these cannot be overriden
|
15
|
-
set(:unicorn_script) { "
|
16
|
-
set(:unicorn_config) { "
|
17
|
-
set(:unicorn_pidfile) { "
|
15
|
+
set(:unicorn_script) { File.join(bin_path, "unicorn") }
|
16
|
+
set(:unicorn_config) { File.join(config_path, "unicorn.rb") }
|
17
|
+
set(:unicorn_pidfile) { File.join(pid_path, "unicorn.pid") }
|
18
18
|
|
19
19
|
monit_config "unicorn", <<EOF
|
20
20
|
check process unicorn
|
21
|
-
with pidfile "<%=
|
22
|
-
start program = "<%=
|
23
|
-
stop program = "<%=
|
21
|
+
with pidfile "<%= unicorn_pidfile %>"
|
22
|
+
start program = "<%= unicorn_script %> start" with timeout 60 seconds
|
23
|
+
stop program = "<%= unicorn_script %> stop"
|
24
24
|
EOF
|
25
25
|
|
26
26
|
namespace :deploy do
|
@@ -43,10 +43,12 @@ EOF
|
|
43
43
|
namespace :unicorn do
|
44
44
|
desc "Generate unicorn configuration files"
|
45
45
|
task :setup, :roles => :app, :except => { :no_release => true } do
|
46
|
-
upload_template_file("unicorn.rb",
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
upload_template_file("unicorn.rb",
|
47
|
+
unicorn_config,
|
48
|
+
:mode => "0644")
|
49
|
+
upload_template_file("unicorn.sh",
|
50
|
+
unicorn_script,
|
51
|
+
:mode => "0755")
|
50
52
|
end
|
51
53
|
|
52
54
|
desc "Kill unicorn (this should only be used if all else fails)"
|
data/lib/capper/utils/monit.rb
CHANGED
@@ -2,8 +2,10 @@ class Capper
|
|
2
2
|
module Utils
|
3
3
|
module Monit
|
4
4
|
|
5
|
-
def monit_config(name, body)
|
6
|
-
set(:monit_configs, fetch(:monit_configs, {}).merge(name =>
|
5
|
+
def monit_config(name, body, options={})
|
6
|
+
set(:monit_configs, fetch(:monit_configs, {}).merge(name => {
|
7
|
+
:options => options, :body => body
|
8
|
+
}))
|
7
9
|
end
|
8
10
|
|
9
11
|
end
|
@@ -19,9 +19,12 @@ class Capper
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def upload_template_string(str, path, options={})
|
22
|
-
|
23
|
-
|
22
|
+
upload_template(path, options) do |server|
|
23
|
+
str
|
24
|
+
end
|
25
|
+
end
|
24
26
|
|
27
|
+
def upload_template(path, options={})
|
25
28
|
if task = current_task
|
26
29
|
servers = find_servers_for_task(task, options)
|
27
30
|
else
|
@@ -33,36 +36,12 @@ class Capper
|
|
33
36
|
end
|
34
37
|
|
35
38
|
servers.each do |server|
|
36
|
-
|
39
|
+
erb = Erubis::Eruby.new(yield server)
|
40
|
+
result = erb.result(binding())
|
37
41
|
put(result, path, options.merge!(:host => server.host))
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
41
|
-
# this allows for server specific variables. example:
|
42
|
-
#
|
43
|
-
# set :unicorn_worker_processes, {
|
44
|
-
# "app1.example.com" => 4,
|
45
|
-
# "app2.example.com" => 8,
|
46
|
-
# }
|
47
|
-
def get_binding(prefix, server)
|
48
|
-
b = binding()
|
49
|
-
|
50
|
-
variables.keys.select do |k|
|
51
|
-
k =~ /^#{prefix}_/
|
52
|
-
end.each do |k|
|
53
|
-
v = fetch(k)
|
54
|
-
|
55
|
-
if v.kind_of?(Hash)
|
56
|
-
eval("set(:#{k}, \"#{v[server] || v["default"]}\")", b)
|
57
|
-
else
|
58
|
-
eval("set(:#{k}, \"#{v}\")", b)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
return b
|
63
|
-
end
|
64
|
-
private :get_binding
|
65
|
-
|
66
45
|
end
|
67
46
|
end
|
68
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-08-22 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: erubis
|
16
|
-
requirement: &
|
16
|
+
requirement: &15467440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *15467440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: capistrano
|
27
|
-
requirement: &
|
27
|
+
requirement: &15467000 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *15467000
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: capistrano_colors
|
38
|
-
requirement: &
|
38
|
+
requirement: &15466580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *15466580
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &15466080 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 1.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *15466080
|
58
58
|
description: Capistrano is a collection of opinionated Capistrano recipes
|
59
59
|
email:
|
60
60
|
- bb@xnull.de
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/capper/base.rb
|
77
77
|
- lib/capper/bundler.rb
|
78
78
|
- lib/capper/config.rb
|
79
|
+
- lib/capper/delayed_job.rb
|
79
80
|
- lib/capper/gem.rb
|
80
81
|
- lib/capper/git.rb
|
81
82
|
- lib/capper/hoptoad.rb
|
@@ -84,6 +85,7 @@ files:
|
|
84
85
|
- lib/capper/rails.rb
|
85
86
|
- lib/capper/rvm.rb
|
86
87
|
- lib/capper/sass.rb
|
88
|
+
- lib/capper/templates/delayed_job.sh.erb
|
87
89
|
- lib/capper/templates/unicorn.rb.erb
|
88
90
|
- lib/capper/templates/unicorn.sh.erb
|
89
91
|
- lib/capper/unicorn.rb
|