capper 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capper (0.2.4)
4
+ capper (0.3.6)
5
5
  capistrano
6
6
  capistrano_colors
7
7
  erubis
data/capper.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "capper"
5
- s.version = "0.3.6"
5
+ s.version = "0.4.0"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.licenses = ["MIT"]
8
8
  s.authors = ["Benedikt Böhm"]
data/lib/capper/base.rb CHANGED
@@ -16,6 +16,9 @@ include Capper::Utils::Templates
16
16
  require 'capper/utils/multistage'
17
17
  include Capper::Utils::Multistage
18
18
 
19
+ require 'capper/utils/monit'
20
+ include Capper::Utils::Monit
21
+
19
22
  # define a bunch of defaults that make sense
20
23
  Capper.load do
21
24
  # do not trace by default
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/base' unless defined?(Capper)
2
+
3
+ Capper.load do
4
+ set(:monitrc) { "#{deploy_to}/.monitrc.local" }
5
+
6
+ namespace :monit do
7
+ task :setup do
8
+ str = fetch(:monit_configs, {}).join("\n\n")
9
+ upload_template_string(str, monitrc, :mode => "0644")
10
+ end
11
+
12
+ task :reload do
13
+ run "monit reload &>/dev/null"
14
+ end
15
+ end
16
+
17
+ after "deploy:update_code", "monit:setup"
18
+ before "deploy:restart", "monit:reload"
19
+ end
@@ -46,8 +46,15 @@ end
46
46
  before_fork do |server, worker|
47
47
  # the following is highly recomended for Rails + "preload_app true"
48
48
  # as there's no need for the master process to hold a connection
49
- defined?(ActiveRecord::Base) and
49
+ if defined?(ActiveRecord::Base)
50
50
  ActiveRecord::Base.connection.disconnect!
51
+ end
52
+
53
+ if defined?(DataObjects::Pooling)
54
+ DataObjects::Pooling.pools.each do |pool|
55
+ pool.dispose
56
+ end
57
+ end
51
58
 
52
59
  # This allows a new master process to incrementally
53
60
  # phase out the old master process with SIGTTOU to avoid a
@@ -66,8 +73,17 @@ end
66
73
 
67
74
  after_fork do |server, worker|
68
75
  # the following is *required* for Rails + "preload_app true",
69
- defined?(ActiveRecord::Base) and
76
+ if defined?(ActiveRecord::Base)
70
77
  ActiveRecord::Base.establish_connection
78
+ end
79
+
80
+ if defined?(Rails)
81
+ if defined?(ActiveSupport::Cache::DalliStore)
82
+ if Rails.cache.is_a?(ActiveSupport::Cache::DalliStore)
83
+ Rails.cache.reset
84
+ end
85
+ end
86
+ end
71
87
 
72
88
  # if preload_app is true, then you may also want to check and
73
89
  # restart any other shared sockets/descriptors such as Memcached,
@@ -16,6 +16,13 @@ Capper.load do
16
16
  set(:unicorn_config) { "#{config_path}/unicorn.rb" }
17
17
  set(:unicorn_pidfile) { "#{shared_path}/pids/unicorn.pid" }
18
18
 
19
+ monit_config "unicorn", <<EOF
20
+ check process unicorn
21
+ with pidfile "<%= shared_path %>/pids/unicorn.pid"
22
+ start program = "<%= bin_path %>/unicorn start" with timeout 60 seconds
23
+ stop program = "<%= bin_path %>/unicorn stop"
24
+ EOF
25
+
19
26
  namespace :deploy do
20
27
  desc "Start unicorn"
21
28
  task :start, :roles => :app, :except => { :no_release => true } do
@@ -36,10 +43,10 @@ Capper.load do
36
43
  namespace :unicorn do
37
44
  desc "Generate unicorn configuration files"
38
45
  task :setup, :roles => :app, :except => { :no_release => true } do
39
- upload_template("unicorn.rb", unicorn_config,
40
- :mode => "0644", :prefix => "unicorn")
41
- upload_template("unicorn.sh", unicorn_script,
42
- :mode => "0755", :prefix => "unicorn")
46
+ upload_template_file("unicorn.rb", unicorn_config,
47
+ :mode => "0644", :prefix => "unicorn")
48
+ upload_template_file("unicorn.sh", unicorn_script,
49
+ :mode => "0755", :prefix => "unicorn")
43
50
  end
44
51
 
45
52
  desc "Kill unicorn (this should only be used if all else fails)"
@@ -0,0 +1,11 @@
1
+ class Capper
2
+ module Utils
3
+ module Monit
4
+
5
+ def monit_config(name, body)
6
+ set(:monit_configs, fetch(:monit_configs, []) << "# #{name}\n#{body}")
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -7,14 +7,19 @@ class Capper
7
7
  # render an erb template from config/deploy/templates to the current
8
8
  # server list. this will render and upload templates serially using a
9
9
  # server-specific @variables binding. see get_binding for details.
10
- def upload_template(name, path, options={})
10
+ def upload_template_file(name, path, options={})
11
11
  template = "config/deploy/templates/#{name}.erb"
12
12
 
13
13
  unless File.exist?(template)
14
14
  template = File.expand_path("../../templates/#{name}.erb", __FILE__)
15
15
  end
16
16
 
17
- erb = Erubis::Eruby.new(File.open(template).read)
17
+ str = File.open(template).read
18
+ upload_template_string(str, path, options)
19
+ end
20
+
21
+ def upload_template_string(str, path, options={})
22
+ erb = Erubis::Eruby.new(str)
18
23
  prefix = options.delete(:prefix)
19
24
 
20
25
  if task = current_task
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.3.6
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-15 00:00:00.000000000Z
12
+ date: 2011-08-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: erubis
16
- requirement: &12039700 !ruby/object:Gem::Requirement
16
+ requirement: &11917960 !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: *12039700
24
+ version_requirements: *11917960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: capistrano
27
- requirement: &12039260 !ruby/object:Gem::Requirement
27
+ requirement: &11917520 !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: *12039260
35
+ version_requirements: *11917520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: capistrano_colors
38
- requirement: &12038840 !ruby/object:Gem::Requirement
38
+ requirement: &11917100 !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: *12038840
46
+ version_requirements: *11917100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &12038340 !ruby/object:Gem::Requirement
49
+ requirement: &11916600 !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: *12038340
57
+ version_requirements: *11916600
58
58
  description: Capistrano is a collection of opinionated Capistrano recipes
59
59
  email:
60
60
  - bb@xnull.de
@@ -79,6 +79,7 @@ files:
79
79
  - lib/capper/gem.rb
80
80
  - lib/capper/git.rb
81
81
  - lib/capper/hoptoad.rb
82
+ - lib/capper/monit.rb
82
83
  - lib/capper/multistage.rb
83
84
  - lib/capper/rails.rb
84
85
  - lib/capper/rvm.rb
@@ -86,6 +87,7 @@ files:
86
87
  - lib/capper/templates/unicorn.sh.erb
87
88
  - lib/capper/unicorn.rb
88
89
  - lib/capper/utils/load.rb
90
+ - lib/capper/utils/monit.rb
89
91
  - lib/capper/utils/multistage.rb
90
92
  - lib/capper/utils/templates.rb
91
93
  - lib/capper/whenever.rb