capistrano-pumaio 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -25,12 +25,24 @@ cap puma:monit:disable # Disable and stop monit services for puma
25
25
  cap puma:monit:enable # Enable monit services for puma
26
26
  cap puma:monit:monitor # Monitor puma
27
27
  cap puma:monit:restart # Restart monit services for puma
28
+ cap puma:monit:phased_restart # Phased-Restart monit services for puma
28
29
  cap puma:monit:setup # Setup Puma monit-service
29
30
  cap puma:monit:start # Start monit services for puma (will also tr...
30
31
  cap puma:monit:stop # Stop monit services for puma (will also sto...
31
32
  cap puma:monit:unmonitor # Purge puma monit configuration
32
33
  ```
33
34
 
35
+ _Note about phased restarts:_
36
+
37
+ _It is not possible to have the application preloaded by puma when using phased restarts._
38
+ _You must therefore set the option :puma\_use\_preload\_app to to false in your deploy.rb_
39
+
40
+ _Like this:_
41
+
42
+ ```ruby
43
+ set :puma_use_preload_app, false # If you are going to use phased restarts
44
+ ```
45
+
34
46
  #### Setup in your deploy file
35
47
 
36
48
  You can add this to deploy.rb or env.rb in order to automatically start/stop puma using monit. It is not needed if you use runit to stop/start/restart the service.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.0.9
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "capistrano-pumaio"
8
- s.version = "0.0.8"
8
+ s.version = "0.0.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Leif Ringstad"]
12
- s.date = "2013-07-31"
12
+ s.date = "2013-08-01"
13
13
  s.description = "Capistrano recipes for puma using runit and monit."
14
14
  s.email = "leifcr@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -16,6 +16,8 @@ Capistrano::Configuration.instance(true).load do
16
16
  _cset :puma_control_file, "#{File.join(fetch(:sockets_path), "pumactl.sock")}"
17
17
  _cset :puma_control_url, "unix://#{fetch(:puma_control_file)}"
18
18
 
19
+ _cset :puma_use_preload_app, true # This must be set to false if phased restarts should be used
20
+
19
21
  _cset :puma_activate_control_app, true
20
22
 
21
23
  _cset :puma_on_restart_active, true
@@ -8,17 +8,29 @@ Capistrano::Configuration.instance(true).load do
8
8
  # enable service after update in case it has not been setup or is disabled
9
9
  # Service should probably be started as well?
10
10
  after "deploy:update", "puma:runit:enable"
11
- before "puma:runit:setup", "puma:runit:flush_sockets"
11
+ before "puma:runit:setup", "puma:flush_sockets"
12
+ before "puma:runit:setup", "puma:setup"
12
13
  before "puma:runit:quit", "puma:runit:stop"
13
14
 
14
15
  namespace :puma do
16
+
17
+ desc "Setup Puma configuration"
18
+ task :setup, :roles => :app do
19
+ Capistrano::BaseHelper.prepare_path(File.join(fetch(:shared_path), "sockets"), fetch(:user), fetch(:group))
20
+
21
+ # Create puma configuration file
22
+ Capistrano::BaseHelper::generate_and_upload_config(fetch(:puma_local_config), fetch(:puma_remote_config))
23
+ end
24
+
25
+ desc "Flush Puma sockets, as they can end up 'hanging around'"
26
+ task :flush_sockets, :roles => :app do
27
+ run "rm -f #{fetch(:puma_socket_file)}; rm -f #{fetch(:puma_control_file)}"
28
+ end
29
+
15
30
  namespace :runit do
16
31
  desc "Setup Puma runit-service"
17
32
  task :setup, :roles => :app do
18
- Capistrano::BaseHelper.prepare_path(File.join(fetch(:shared_path), "sockets"), fetch(:user), fetch(:group))
19
33
 
20
- # Create puma configuration file
21
- Capistrano::BaseHelper::generate_and_upload_config(fetch(:puma_local_config), fetch(:puma_remote_config))
22
34
 
23
35
  # Create runit config
24
36
  Capistrano::RunitBase.create_service_dir(puma_runit_service_name)
@@ -34,8 +46,8 @@ Capistrano::Configuration.instance(true).load do
34
46
  Capistrano::RunitBase.make_service_scripts_executeable(puma_runit_service_name)
35
47
  # Set correct permissions/owner on log path
36
48
  Capistrano::RunitBase.create_and_permissions_on_path(fetch(:puma_log_path))
37
- end
38
-
49
+ end
50
+
39
51
  desc "Enable Puma runit-service"
40
52
  task :enable, :roles => :app do
41
53
  Capistrano::RunitBase.enable_service(puma_runit_service_name)
@@ -70,13 +82,56 @@ Capistrano::Configuration.instance(true).load do
70
82
 
71
83
  desc "Restart Puma runit-service"
72
84
  task :restart, :roles => :app do
73
- # Send USR2 to puma in order to restart it....
74
- Capistrano::RunitBase.control_service(puma_runit_service_name, "2")
85
+ result = nil
86
+ started = false
87
+
88
+ # It is not possible to see if a restart is in progress using the pumactl tool as of now.
89
+
90
+ # restarting = false
91
+ # # check if puma is already performing a restart
92
+ # invoke_command("cd #{fetch(:current_path)}; [[ $(#{fetch(:puma_control)} -S #{fetch(:puma_state_file)} status) == *restart* ]] && echo 'restarting';true") do |ch, stream, out|
93
+ # result = (/restart/ =~ out)
94
+ # end
95
+ # restarting = true unless result.nil?
96
+ # result = nil
97
+
98
+ # if restarting == false
99
+ # check if it is running
100
+ invoke_command("cd #{fetch(:current_path)}; [[ $(#{fetch(:puma_control)} -S #{fetch(:puma_state_file)} status) == *started* ]] && echo 'started';true") do |ch, stream, out|
101
+ result = (/started/ =~ out)
102
+ end
103
+ started = true unless result.nil?
104
+
105
+ if started == true
106
+ logger.info("\nRestarting puma")
107
+ # Send USR2 to puma in order to restart it....
108
+ Capistrano::RunitBase.control_service(puma_runit_service_name, "2")
109
+ else
110
+ logger.important("\nStarting puma, (wasn't running before)")
111
+ Capistrano::RunitBase.start_service(puma_runit_service_name)
112
+ end
113
+ # end
75
114
  end
76
-
77
- desc "Flush Puma sockets, as they can end up 'hanging around'"
78
- task :flush_sockets, :roles => :app do
79
- run "rm -f #{fetch(:puma_socket_file)}; rm -f #{fetch(:puma_control_file)}"
115
+
116
+ desc "Phased Restart of Puma"
117
+ task :phased_restart, :roles => :app do
118
+ result = nil
119
+ started = false
120
+
121
+ # check if it is running
122
+ invoke_command("cd #{fetch(:current_path)}; [[ $(#{fetch(:puma_control)} -S #{fetch(:puma_state_file)} status) == *started* ]] && echo 'started';true") do |ch, stream, out|
123
+ result = (/started/ =~ out)
124
+ end
125
+ started = true unless result.nil?
126
+
127
+ if started == true
128
+ # Send USR1 to puma in order to restart it....
129
+ logger.info("\nPhased restart of puma")
130
+ Capistrano::RunitBase.control_service(puma_runit_service_name, "1")
131
+ else
132
+ logger.important("\nStarting puma, (wasn't running before)")
133
+ Capistrano::RunitBase.start_service(puma_runit_service_name)
134
+ end
80
135
  end
81
136
 
82
137
  desc "Purge Puma runit configuration"
@@ -84,7 +139,7 @@ Capistrano::Configuration.instance(true).load do
84
139
  Capistrano::RunitBase.force_control_service(puma_runit_service_name, "force-stop", true)
85
140
  Capistrano::RunitBase.purge_service(puma_runit_service_name)
86
141
  end
87
-
142
+
88
143
  end
89
144
  end
90
145
  end
@@ -8,8 +8,11 @@ state_path '<%= c.fetch(:puma_state_file) %>'
8
8
  environment '<%= "#{Capistrano::BaseHelper.environment}" %>'
9
9
  <%= "activate_control_app '#{c.fetch(:puma_control_url)}'" if c.fetch(:puma_activate_control_app) %>
10
10
 
11
- # Must preload application in case there are errors, if not, infinite restarts will happen
12
- preload_app!
11
+ # In some cases preloading the app is best to avoid some infinite restart loops, however, it cannot be used in
12
+ # combination with phased restart.
13
+ <%= "preload_app!" if c.fetch(:puma_use_preload_app) %>
14
+
15
+ directory '<%= File.join(c.fetch(:deploy_to), "current") %>'
13
16
 
14
17
  # TODO - fix restart block!
15
18
  # <%= "on_restart do" if c.fetch(:puma_on_restart_active) %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-pumaio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-31 00:00:00.000000000 Z
12
+ date: 2013-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  segments:
120
120
  - 0
121
- hash: -3189334886428706099
121
+ hash: 1012333913118032942
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  none: false
124
124
  requirements: