capistrano-sneakers 0.1.1 → 1.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f27762c256ad0cf936ee3b7b9f8d164fa902030
4
- data.tar.gz: fa03efb4683745483ce07a6ecb3cd74de14965f6
3
+ metadata.gz: 978e28a0077d18528ca6c307d75c056f56d3d69c
4
+ data.tar.gz: ba45e83575f1a3c8de695f88dd5cd76a9939d55b
5
5
  SHA512:
6
- metadata.gz: 9c880d4f8aab9f96aaea8f4e505c8d04d1d684b5547005406a86e885f207b2a02e80101062af5452e116d4fed824b64dbad8e32f00417653d9410565d6e9774e
7
- data.tar.gz: cde49c7a7a6dceea52bad443b22dceb0dd15e6fa202aec60944de22380ac1a7424b06db46fffb2558d365eb0272fd7a9b7e870ff1c107efbaa19fee9d522efdd
6
+ metadata.gz: 7c5eb0c4d5afa78b5e06064851a7ca6ce9485b13e001ab7d95befb993b1fc8d41ec951294f3acbcc88f3d3b1c8c223d082418d69c0d3791c068b70f5ff07fa6b
7
+ data.tar.gz: 233f650045ca9cd053d16369004e65d0a08d2e518a13e48cde01e1cd29b4a9e31b57a5fabe432428d0c106922e5ae869bd6690fb74b3c701f5331f85ee14902f
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ builds/**
data/README.md CHANGED
@@ -37,9 +37,12 @@ Configurable options, shown here with defaults:
37
37
  ```
38
38
 
39
39
  ## Contributors
40
-
40
+ - [Karl Kloppenborg](https://github.com/inventionlabsSydney)
41
41
  - [Andrew Babichev](https://github.com/Tensho)
42
42
  - [NaixSpirit](https://github.com/NaixSpirit)
43
+ - [hpetru](https://github.com/hpetru)
44
+ - [jhollinger](https://github.com/jhollinger)
45
+ - [redrick](https://github.com/redrick)
43
46
 
44
47
  ## Contributing
45
48
 
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.required_ruby_version = '>= 2.0.0'
21
21
 
22
22
  spec.add_dependency 'capistrano', '>= 3.9.0'
23
- spec.add_dependency 'sneakers'
23
+ spec.add_dependency 'sneakers', '>= 2.6'
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.7"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
@@ -0,0 +1,97 @@
1
+ module Capistrano
2
+ module Sneakers
3
+ module HelperMethods
4
+ def sneakers_each_process_with_index(reverse = false, &block)
5
+ _pid_files = sneakers_pid_files
6
+ _pid_files.reverse! if reverse
7
+ _pid_files.each_with_index do |pid_file, idx|
8
+ within release_path do
9
+ yield(pid_file, idx)
10
+ end
11
+ end
12
+ end
13
+
14
+ def sneakers_pid_files
15
+ sneakers_roles = Array(fetch(:sneakers_roles))
16
+ sneakers_roles.select! { |role| host.roles.include?(role) }
17
+ sneakers_roles.flat_map do |role|
18
+ processes = fetch(:sneakers_processes)
19
+ if processes == 1
20
+ fetch(:sneakers_pid)
21
+ else
22
+ Array.new(processes) { |idx| fetch(:sneakers_pid).gsub(/\.pid$/, "-#{idx}.pid") }
23
+ end
24
+ end
25
+ end
26
+
27
+ def sneakers_pid_file_exists?(pid_file)
28
+ test(*("[ -f #{pid_file} ]").split(' '))
29
+ end
30
+
31
+ def sneakers_process_exists?(pid_file)
32
+ test(*("kill -0 $( cat #{pid_file} )").split(' '))
33
+ end
34
+
35
+ def quiet_sneakers(pid_file)
36
+ if fetch(:sneakers_use_signals) || fetch(:sneakers_run_config)
37
+ execute :kill, "-USR1 `cat #{pid_file}`"
38
+ else
39
+ begin
40
+ execute :bundle, :exec, :sneakersctl, 'quiet', "#{pid_file}"
41
+ rescue SSHKit::Command::Failed
42
+ # If gems are not installed eq(first deploy) and sneakers_default_hooks as active
43
+ warn 'sneakersctl not found (ignore if this is the first deploy)'
44
+ end
45
+ end
46
+ end
47
+
48
+ def stop_sneakers(pid_file)
49
+ if fetch(:sneakers_run_config) == true
50
+ execute :kill, "-SIGTERM `cat #{pid_file}`"
51
+ else
52
+ if fetch(:stop_sneakers_in_background, fetch(:sneakers_run_in_background))
53
+ if fetch(:sneakers_use_signals)
54
+ background :kill, "-TERM `cat #{pid_file}`"
55
+ else
56
+ background :bundle, :exec, :sneakersctl, 'stop', "#{pid_file}", fetch(:sneakers_timeout)
57
+ end
58
+ else
59
+ execute :bundle, :exec, :sneakersctl, 'stop', "#{pid_file}", fetch(:sneakers_timeout)
60
+ end
61
+ end
62
+ end
63
+
64
+ def start_sneakers(pid_file, idx = 0)
65
+ if fetch(:sneakers_run_config) == true
66
+ # Use sneakers configuration prebuilt in
67
+ raise "[ set :workers, ['worker1', 'workerN'] ] not configured properly, please configure the workers you wish to use" if fetch(:sneakers_workers).nil? or fetch(:sneakers_workers) == false or !fetch(:sneakers_workers).kind_of? Array
68
+
69
+ workers = fetch(:sneakers_workers).compact.join(',')
70
+
71
+ info "Starting the sneakers processes"
72
+
73
+ with rails_env: fetch(:sneakers_env), workers: workers do
74
+ rake 'sneakers:run'
75
+ end
76
+ end
77
+ end
78
+
79
+ def sneakers_switch_user(role, &block)
80
+ user = sneakers_user(role)
81
+ if user == role.user
82
+ block.call
83
+ else
84
+ as user do
85
+ block.call
86
+ end
87
+ end
88
+ end
89
+
90
+ def sneakers_user(role)
91
+ properties = role.properties
92
+ properties.fetch(:sneakers_user) || fetch(:sneakers_user) || properties.fetch(:run_as) || role.user
93
+ end
94
+ end
95
+ end
96
+ end
97
+
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Sneakers
3
- VERSION = "0.1.1"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ namespace :load do
2
2
  task :defaults do
3
3
  set :monit_bin, '/usr/bin/monit'
4
4
  set :sneakers_monit_default_hooks, true
5
- set :sneakers_monit_conf_dir, -> { '/etc/monit/conf.d' }
5
+ set :sneakers_monit_conf_dir, '/etc/monit/conf.d'
6
6
  set :sneakers_monit_use_sudo, true
7
7
  set :sneakers_monit_templates_path, 'config/deploy/templates'
8
8
  end
@@ -20,7 +20,7 @@ namespace :sneakers do
20
20
  namespace :monit do
21
21
  task :add_default_hooks do
22
22
  before 'deploy:updating', 'sneakers:monit:unmonitor'
23
- after 'deploy:published', 'sneakers:monit:monitor'
23
+ after 'deploy:published', 'sneakers:monit:monitor'
24
24
  end
25
25
 
26
26
  desc 'Config Sneakers monit-service'
@@ -29,7 +29,7 @@ namespace :sneakers do
29
29
  @role = role
30
30
  upload_sneakers_template 'sneakers_monit', "#{fetch(:tmp_dir)}/monit.conf", @role
31
31
 
32
- mv_command = "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:sneakers_monit_conf_dir)}/#{sneakers_service_name}.conf"
32
+ mv_command = "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:sneakers_monit_conf_dir)}/#{sneakers_monit_service_name}.conf"
33
33
  sudo_if_needed mv_command
34
34
 
35
35
  sudo_if_needed "#{fetch(:monit_bin)} reload"
@@ -39,40 +39,49 @@ namespace :sneakers do
39
39
  desc 'Monitor Sneakers monit-service'
40
40
  task :monitor do
41
41
  on roles(fetch(:sneakers_roles)) do
42
- sudo_if_needed "#{fetch(:monit_bin)} monitor #{sneakers_service_name}"
42
+ begin
43
+ sudo_if_needed "#{fetch(:monit_bin)} monitor #{sneakers_monit_service_name}"
44
+ rescue
45
+ invoke 'sneakers:monit:config'
46
+ sudo_if_needed "#{fetch(:monit_bin)} monitor #{sneakers_monit_service_name}"
47
+ end
43
48
  end
44
49
  end
45
50
 
46
51
  desc 'Unmonitor Sneakers monit-service'
47
52
  task :unmonitor do
48
53
  on roles(fetch(:sneakers_roles)) do
49
- sudo_if_needed "#{fetch(:monit_bin)} unmonitor #{sneakers_service_name}"
54
+ begin
55
+ sudo_if_needed "#{fetch(:monit_bin)} unmonitor #{sneakers_monit_service_name}"
56
+ rescue
57
+ # no worries here
58
+ end
50
59
  end
51
60
  end
52
61
 
53
62
  desc 'Start Sneakers monit-service'
54
63
  task :start do
55
64
  on roles(fetch(:sneakers_roles)) do
56
- sudo_if_needed "#{fetch(:monit_bin)} start #{sneakers_service_name}"
65
+ sudo_if_needed "#{fetch(:monit_bin)} start #{sneakers_monit_service_name}"
57
66
  end
58
67
  end
59
68
 
60
69
  desc 'Stop Sneakers monit-service'
61
70
  task :stop do
62
71
  on roles(fetch(:sneakers_roles)) do
63
- sudo_if_needed "#{fetch(:monit_bin)} stop #{sneakers_service_name}"
72
+ sudo_if_needed "#{fetch(:monit_bin)} stop #{sneakers_monit_service_name}"
64
73
  end
65
74
  end
66
75
 
67
76
  desc 'Restart Sneakers monit-service'
68
77
  task :restart do
69
78
  on roles(fetch(:sneakers_roles)) do
70
- sudo_if_needed "#{fetch(:monit_bin)} restart #{sneakers_service_name}"
79
+ sudo_if_needed "#{fetch(:monit_bin)} restart #{sneakers_monit_service_name}"
71
80
  end
72
81
  end
73
82
 
74
- def sneakers_service_name
75
- fetch(:sneakers_service_name, "sneakers_#{fetch(:application)}_#{fetch(:sneakers_env)}")
83
+ def sneakers_monit_service_name
84
+ fetch(:sneakers_monit_service_name, "sneakers_#{fetch(:application)}_#{fetch(:sneakers_env)}")
76
85
  end
77
86
 
78
87
  def sudo_if_needed(command)
@@ -1,3 +1,6 @@
1
+ require 'capistrano/sneakers/helper_methods'
2
+ include Capistrano::Sneakers::HelperMethods
3
+
1
4
  namespace :load do
2
5
  task :defaults do
3
6
  set :sneakers_default_hooks, true
@@ -39,10 +42,10 @@ namespace :sneakers do
39
42
  desc 'Quiet sneakers (stop processing new tasks)'
40
43
  task :quiet do
41
44
  on roles fetch(:sneakers_roles) do |role|
42
- switch_user(role) do
45
+ sneakers_switch_user(role) do
43
46
  if test("[ -d #{current_path} ]")
44
- each_process_with_index(true) do |pid_file, idx|
45
- if pid_file_exists?(pid_file) && process_exists?(pid_file)
47
+ sneakers_each_process_with_index(true) do |pid_file, idx|
48
+ if pid_file_exists?(pid_file) && sneakers_process_exists?(pid_file)
46
49
  quiet_sneakers(pid_file)
47
50
  end
48
51
  end
@@ -54,10 +57,10 @@ namespace :sneakers do
54
57
  desc 'Stop sneakers'
55
58
  task :stop do
56
59
  on roles fetch(:sneakers_roles) do |role|
57
- switch_user(role) do
60
+ sneakers_switch_user(role) do
58
61
  if test("[ -d #{current_path} ]")
59
- each_process_with_index(true) do |pid_file, idx|
60
- if pid_file_exists?(pid_file) && process_exists?(pid_file)
62
+ sneakers_each_process_with_index(true) do |pid_file, idx|
63
+ if sneakers_pid_file_exists?(pid_file) && sneakers_process_exists?(pid_file)
61
64
  stop_sneakers(pid_file)
62
65
  end
63
66
  end
@@ -69,9 +72,9 @@ namespace :sneakers do
69
72
  desc 'Start sneakers'
70
73
  task :start do
71
74
  on roles fetch(:sneakers_roles) do |role|
72
- switch_user(role) do
73
- each_process_with_index do |pid_file, idx|
74
- unless pid_file_exists?(pid_file) && process_exists?(pid_file)
75
+ sneakers_switch_user(role) do
76
+ sneakers_each_process_with_index do |pid_file, idx|
77
+ unless sneakers_pid_file_exists?(pid_file) && sneakers_process_exists?(pid_file)
75
78
  start_sneakers(pid_file, idx)
76
79
  end
77
80
  end
@@ -91,9 +94,9 @@ namespace :sneakers do
91
94
  desc 'Rolling-restart sneakers'
92
95
  task :rolling_restart do
93
96
  on roles fetch(:sneakers_roles) do |role|
94
- switch_user(role) do
95
- each_process_with_index(true) do |pid_file, idx|
96
- if pid_file_exists?(pid_file) && process_exists?(pid_file)
97
+ sneakers_switch_user(role) do
98
+ sneakers_each_process_with_index(true) do |pid_file, idx|
99
+ if sneakers_pid_file_exists?(pid_file) && sneakers_process_exists?(pid_file)
97
100
  stop_sneakers(pid_file)
98
101
  end
99
102
  start_sneakers(pid_file, idx)
@@ -105,10 +108,10 @@ namespace :sneakers do
105
108
  # Delete any pid file not in use
106
109
  task :cleanup do
107
110
  on roles fetch(:sneakers_roles) do |role|
108
- switch_user(role) do
109
- each_process_with_index do |pid_file, idx|
110
- unless process_exists?(pid_file)
111
- if pid_file_exists?(pid_file)
111
+ sneakers_switch_user(role) do
112
+ sneakers_each_process_with_index do |pid_file, idx|
113
+ unless sneakers_process_exists?(pid_file)
114
+ if sneakers_pid_file_exists?(pid_file)
112
115
  execute "rm #{pid_file}"
113
116
  end
114
117
  end
@@ -122,104 +125,13 @@ namespace :sneakers do
122
125
  task :respawn do
123
126
  invoke 'sneakers:cleanup'
124
127
  on roles fetch(:sneakers_roles) do |role|
125
- switch_user(role) do
126
- each_process_with_index do |pid_file, idx|
127
- unless pid_file_exists?(pid_file)
128
+ sneakers_switch_user(role) do
129
+ sneakers_each_process_with_index do |pid_file, idx|
130
+ unless sneakers_pid_file_exists?(pid_file)
128
131
  start_sneakers(pid_file, idx)
129
132
  end
130
133
  end
131
134
  end
132
135
  end
133
136
  end
134
-
135
- def each_process_with_index(reverse = false, &block)
136
- _pid_files = pid_files
137
- _pid_files.reverse! if reverse
138
- _pid_files.each_with_index do |pid_file, idx|
139
- within release_path do
140
- yield(pid_file, idx)
141
- end
142
- end
143
- end
144
-
145
- def pid_files
146
- sneakers_roles = Array(fetch(:sneakers_roles))
147
- sneakers_roles.select! { |role| host.roles.include?(role) }
148
- sneakers_roles.flat_map do |role|
149
- processes = fetch(:sneakers_processes)
150
- if processes == 1
151
- fetch(:sneakers_pid)
152
- else
153
- Array.new(processes) { |idx| fetch(:sneakers_pid).gsub(/\.pid$/, "-#{idx}.pid") }
154
- end
155
- end
156
- end
157
-
158
- def pid_file_exists?(pid_file)
159
- test(*("[ -f #{pid_file} ]").split(' '))
160
- end
161
-
162
- def process_exists?(pid_file)
163
- test(*("kill -0 $( cat #{pid_file} )").split(' '))
164
- end
165
-
166
- def quiet_sneakers(pid_file)
167
- if fetch(:sneakers_use_signals) || fetch(:sneakers_run_config)
168
- execute :kill, "-USR1 `cat #{pid_file}`"
169
- else
170
- begin
171
- execute :bundle, :exec, :sneakersctl, 'quiet', "#{pid_file}"
172
- rescue SSHKit::Command::Failed
173
- # If gems are not installed eq(first deploy) and sneakers_default_hooks as active
174
- warn 'sneakersctl not found (ignore if this is the first deploy)'
175
- end
176
- end
177
- end
178
-
179
- def stop_sneakers(pid_file)
180
- if fetch(:sneakers_run_config) == true
181
- execute :kill, "-SIGTERM `cat #{pid_file}`"
182
- else
183
- if fetch(:stop_sneakers_in_background, fetch(:sneakers_run_in_background))
184
- if fetch(:sneakers_use_signals)
185
- background :kill, "-TERM `cat #{pid_file}`"
186
- else
187
- background :bundle, :exec, :sneakersctl, 'stop', "#{pid_file}", fetch(:sneakers_timeout)
188
- end
189
- else
190
- execute :bundle, :exec, :sneakersctl, 'stop', "#{pid_file}", fetch(:sneakers_timeout)
191
- end
192
- end
193
- end
194
-
195
- def start_sneakers(pid_file, idx = 0)
196
- if fetch(:sneakers_run_config) == true
197
- # Use sneakers configuration prebuilt in
198
- raise "[ set :workers, ['worker1', 'workerN'] ] not configured properly, please configure the workers you wish to use" if fetch(:sneakers_workers).nil? or fetch(:sneakers_workers) == false or !fetch(:sneakers_workers).kind_of? Array
199
-
200
- workers = fetch(:sneakers_workers).compact.join(',')
201
-
202
- info "Starting the sneakers processes"
203
-
204
- with rails_env: fetch(:sneakers_env), workers: workers do
205
- rake 'sneakers:run'
206
- end
207
- end
208
- end
209
-
210
- def switch_user(role, &block)
211
- user = sneakers_user(role)
212
- if user == role.user
213
- block.call
214
- else
215
- as user do
216
- block.call
217
- end
218
- end
219
- end
220
-
221
- def sneakers_user(role)
222
- properties = role.properties
223
- properties.fetch(:sneakers_user) || fetch(:sneakers_user) || properties.fetch(:run_as) || role.user
224
- end
225
137
  end
@@ -1,7 +1,5 @@
1
- # Monit configuration for Sneakers
2
- # Service name: <%= sneakers_service_name %>
3
- #
4
- check process <%= sneakers_service_name %>
1
+ # Monit configuration for Sneakers : <%= fetch(:application) %>
2
+ check process <%= sneakers_monit_service_name %>
5
3
  with pidfile "<%= fetch(:sneakers_pid) %>"
6
4
  start program = "/usr/bin/sudo -iu <%= sneakers_user(@role) %> /bin/bash -c 'cd <%= current_path %> && RAILS_ENV=<%= fetch(:sneakers_env) %> WORKERS=<%= fetch(:sneakers_workers).join(',') %> <%= SSHKit.config.command_map[:rake] %> sneakers:run'"
7
5
  stop program = "/usr/bin/sudo -iu <%= sneakers_user(@role) %> /bin/bash -c 'kill -SIGTERM `cat <%= fetch(:sneakers_pid) %>`'"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-sneakers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Kloppenborg, Andrew Babichev, NaixSpirit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-27 00:00:00.000000000 Z
11
+ date: 2018-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '2.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '2.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +84,7 @@ files:
84
84
  - capistrano-sneakers.gemspec
85
85
  - lib/capistrano-sneakers.rb
86
86
  - lib/capistrano/sneakers.rb
87
+ - lib/capistrano/sneakers/helper_methods.rb
87
88
  - lib/capistrano/sneakers/monit.rb
88
89
  - lib/capistrano/sneakers/version.rb
89
90
  - lib/capistrano/tasks/monit.rake