Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
fix(worker): fix sidekiq quiet/shutdown scripts
Browse files Browse the repository at this point in the history
Resolves #217
  • Loading branch information
ajgon committed May 7, 2019
1 parent 4a58654 commit 59198b9
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 76 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
require: rubocop-performance

Metrics/LineLength:
Max: 120

Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.6.0
ruby-2.6.3
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ group :lint do
gem 'mdl'
gem 'overcommit'
gem 'rubocop'
gem 'rubocop-performance'
gem 'travis'
end

Expand Down
118 changes: 78 additions & 40 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ GEM
specs:
addressable (2.4.0)
ast (2.4.0)
backports (3.12.0)
backports (3.14.0)
bcrypt_pbkdf (1.0.1)
berkshelf (6.3.4)
buff-config (~> 2.0)
buff-extensions (~> 2.0)
Expand All @@ -20,7 +21,7 @@ GEM
ridley (~> 5.0)
solve (~> 4.0)
thor (~> 0.19, < 0.19.2)
brakeman (4.4.0)
brakeman (4.5.0)
buff-config (2.0.0)
buff-extensions (~> 2.0)
varia_model (~> 0.6)
Expand Down Expand Up @@ -86,7 +87,7 @@ GEM
ffi (~> 1.0, >= 1.0.11)
cleanroom (1.0.0)
colorize (0.8.1)
concurrent-ruby (1.1.4)
concurrent-ruby (1.1.5)
coveralls (0.8.19)
json (>= 1.8, < 3)
simplecov (~> 0.12.0)
Expand All @@ -100,16 +101,18 @@ GEM
cucumber-tag_expressions (1.1.1)
diff-lcs (1.3)
docile (1.1.5)
ed25519 (1.2.4)
equatable (0.5.0)
erubis (2.7.0)
ethon (0.12.0)
ffi (>= 1.3.0)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.13.1)
faraday (>= 0.7.4, < 1.0)
fasterer (0.4.2)
fasterer (0.5.1)
colorize (~> 0.7)
ruby_parser (>= 3.12.0)
ruby_parser (>= 3.13.0)
fauxhai (4.1.0)
net-ssh
ffi (1.10.0)
Expand All @@ -132,7 +135,7 @@ GEM
net-http-persistent (~> 2.9)
net-http-pipeline
gherkin (5.1.0)
gssapi (1.2.0)
gssapi (1.3.0)
ffi (>= 1.0.1)
gyoku (1.3.1)
builder (>= 2.1.2)
Expand All @@ -144,14 +147,19 @@ GEM
ipaddress (0.8.3)
jaro_winkler (1.5.2)
json (2.2.0)
kitchen-docker (2.8.0)
kitchen-docker (2.9.0)
test-kitchen (>= 1.0.0)
kitchen-vagrant (1.4.0)
test-kitchen (~> 1.4)
kitchen-vagrant (1.5.2)
test-kitchen (>= 1.4, < 3)
kramdown (1.17.0)
launchy (2.4.3)
addressable (~> 2.3)
libyajl2 (1.2.0)
license-acceptance (1.0.5)
pastel (~> 0.7)
tomlrb (~> 1.2)
tty-box (~> 0.3)
tty-prompt (~> 0.18)
little-plugger (1.1.4)
logging (2.2.2)
little-plugger (~> 1.1)
Expand All @@ -168,7 +176,7 @@ GEM
mixlib-cli (1.7.0)
mixlib-config (2.2.18)
tomlrb
mixlib-install (3.11.11)
mixlib-install (3.11.12)
mixlib-shellout
mixlib-versioning
thor
Expand All @@ -178,24 +186,25 @@ GEM
molinillo (0.6.6)
multi_json (1.13.1)
multipart-post (2.0.0)
necromancer (0.4.0)
net-http-persistent (2.9.4)
net-http-pipeline (1.0.1)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-scp (2.0.0)
net-ssh (>= 2.6.5, < 6.0.0)
net-sftp (2.1.2)
net-ssh (>= 2.6.5)
net-ssh (4.2.0)
net-ssh-gateway (1.3.0)
net-ssh (>= 2.6.5)
net-ssh-gateway (2.0.0)
net-ssh (>= 4.0.0)
net-ssh-multi (1.2.1)
net-ssh (>= 2.6.5)
net-ssh-gateway (>= 1.2.0)
net-telnet (0.1.1)
nio4r (2.3.1)
nokogiri (1.10.1)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
nori (2.6.0)
octokit (4.13.0)
octokit (4.14.0)
sawyer (~> 0.8.0, >= 0.5.3)
ohai (8.26.1)
chef-config (>= 12.5.0.alpha.1, < 14)
Expand All @@ -209,21 +218,22 @@ GEM
plist (~> 3.1)
systemu (~> 2.6.4)
wmi-lite (~> 1.0)
overcommit (0.46.0)
overcommit (0.48.0)
childprocess (~> 0.6, >= 0.6.3)
iniparse (~> 1.4)
parallel (1.14.0)
parser (2.6.0.0)
parallel (1.17.0)
parser (2.6.3.0)
ast (~> 2.4.0)
pastel (0.7.2)
equatable (~> 0.5.0)
tty-color (~> 0.4.0)
plist (3.5.0)
polyglot (0.3.5)
powerpack (0.1.2)
proxifier (1.0.3)
psych (3.1.0)
pusher-client (0.6.2)
json
websocket (~> 1.0)
rack (2.0.6)
rack (2.0.7)
rainbow (3.0.0)
rake (12.3.2)
retryable (2.0.4)
Expand Down Expand Up @@ -251,10 +261,10 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
rspec-expectations (3.8.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-its (1.2.0)
rspec-its (1.3.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.8.0)
Expand All @@ -264,31 +274,31 @@ GEM
rspec_junit_formatter (0.2.3)
builder (< 4)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (0.65.0)
rubocop (0.68.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
psych (>= 3.1.0)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
unicode-display_width (>= 1.4.0, < 1.6)
rubocop-performance (1.2.0)
rubocop (>= 0.68.0)
ruby-progressbar (1.10.0)
ruby_parser (3.12.0)
ruby_parser (3.13.1)
sexp_processor (~> 4.9)
rubyntlm (0.6.2)
rubyzip (1.2.2)
rufus-lru (1.1.0)
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
sawyer (0.8.2)
addressable (>= 2.3.5)
faraday (> 0.8, < 2.0)
semverse (2.0.0)
serverspec (2.41.3)
multi_json
rspec (~> 3.0)
rspec-its
specinfra (~> 2.72)
sexp_processor (4.11.0)
sexp_processor (4.12.0)
sfl (2.3)
simplecov (0.12.0)
docile (~> 1.1.0)
Expand All @@ -298,21 +308,29 @@ GEM
solve (4.0.2)
molinillo (~> 0.6)
semverse (>= 1.1, < 4.0)
specinfra (2.76.9)
specinfra (2.77.1)
net-scp
net-ssh (>= 2.7)
net-telnet (= 0.1.1)
sfl
strings (0.1.5)
strings-ansi (~> 0.1)
unicode-display_width (~> 1.5)
unicode_utils (~> 1.4)
strings-ansi (0.1.0)
syslog-logger (1.6.8)
systemu (2.6.5)
term-ansicolor (1.7.1)
tins (~> 1.0)
test-kitchen (1.24.0)
test-kitchen (2.2.2)
bcrypt_pbkdf (~> 1.0)
ed25519 (~> 1.2)
license-acceptance (>= 0.2.16, < 2.0)
mixlib-install (~> 3.6)
mixlib-shellout (>= 1.2, < 3.0)
net-scp (~> 1.1)
net-ssh (>= 2.9, < 5.0)
net-ssh-gateway (~> 1.2)
net-scp (>= 1.1, < 3.0)
net-ssh (>= 2.9, < 6.0)
net-ssh-gateway (>= 1.2, < 3.0)
thor (~> 0.19)
winrm (~> 2.0)
winrm-elevated (~> 1.0)
Expand All @@ -333,15 +351,33 @@ GEM
typhoeus (~> 0.6, >= 0.6.8)
treetop (1.6.10)
polyglot (~> 0.3)
tty-box (0.3.0)
pastel (~> 0.7.2)
strings (~> 0.1.4)
tty-cursor (~> 0.6.0)
tty-color (0.4.3)
tty-cursor (0.6.1)
tty-prompt (0.18.1)
necromancer (~> 0.4.0)
pastel (~> 0.7.0)
timers (~> 4.0)
tty-cursor (~> 0.6.0)
tty-reader (~> 0.5.0)
tty-reader (0.5.0)
tty-cursor (~> 0.6.0)
tty-screen (~> 0.6.4)
wisper (~> 2.0.0)
tty-screen (0.6.5)
typhoeus (0.8.0)
ethon (>= 0.8.0)
unicode-display_width (1.4.1)
unicode-display_width (1.5.0)
unicode_utils (1.4.0)
uuidtools (2.1.5)
varia_model (0.6.0)
buff-extensions (~> 2.0)
hashie (>= 2.0.2, < 4.0.0)
websocket (1.2.8)
winrm (2.3.1)
winrm (2.3.2)
builder (>= 2.1.2)
erubis (~> 2.7)
gssapi (~> 1.2)
Expand All @@ -358,6 +394,7 @@ GEM
logging (>= 1.6.1, < 3.0)
rubyzip (~> 1.1)
winrm (~> 2.0)
wisper (2.0.0)
wmi-lite (1.0.2)

PLATFORMS
Expand All @@ -379,6 +416,7 @@ DEPENDENCIES
overcommit
rspec
rubocop
rubocop-performance
test-kitchen
travis

Expand Down
7 changes: 4 additions & 3 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ bash -c "overcommit --sign && overcommit -r && rspec"

## Integration Testing

To run integration tests you need [Chef Development Kit](https://downloads.chef.io/chefdk).
To run integration tests you need [Chef Development Kit](https://downloads.chef.io/chefdk)
and [Vagrant](https://www.vagrantup.com/).
After installing it, invoke:

```
chef exec bundle install -j 4 --path vendor
sudo chef exec bundle exec rake integration:docker
kitchen converge
kitchen verify
```
35 changes: 10 additions & 25 deletions libraries/drivers_worker_sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,30 @@ def add_sidekiq_config

def quiet_sidekiq
(1..process_count).each do |process_number|
pid_file = pid_file(process_number)
Chef::Log.info("Quiet Sidekiq process if exists: #{pid_file}")
next unless File.file?(pid_file) && pid_exists?(File.open(pid_file).read)
Chef::Log.info("Quiet Sidekiq process if exists: no. #{process_number}")

execute_sidekiqctl 'quiet', pid_file
context.execute(
"/bin/su - #{node['deployer']['user']} -c \"ps -ax | grep 'bundle exec sidekiq' | " \
"grep sidekiq_#{process_number}.yml | grep -v grep | awk '{print $1}' | xargs kill -TSTP\""
)
end
end

def stop_sidekiq
(1..process_count).each do |process_number|
pid_file = pid_file(process_number)
timeout = (out[:config]['timeout'] || 8).to_i
Chef::Log.info("Stop Sidekiq process if exists: no. #{process_number}")

execute_sidekiqctl 'stop', pid_file, timeout
context.execute(
"timeout #{timeout} /bin/su - #{node['deployer']['user']} -c \"ps -ax | grep 'bundle exec sidekiq' | " \
"grep sidekiq_#{process_number}.yml | grep -v grep | awk '{print $1}' | xargs kill -TERM\""
)
end
end

def pid_file(process_number)
"/run/lock/#{app['shortname']}/sidekiq_#{app['shortname']}-#{process_number}.pid"
end

def pid_exists?(pid)
Process.getpgid(pid.to_i)
true
rescue Errno::ESRCH
false
end

def configuration
JSON.parse(out[:config].to_json, symbolize_names: true)
end

def execute_sidekiqctl(*params)
context.execute(
"/bin/su - #{node['deployer']['user']} -c 'cd #{File.join(deploy_dir(app), 'current')} && " \
"#{environment.map { |k, v| "#{k}=\"#{v}\"" }.join(' ')} " \
"bundle exec sidekiqctl #{params.map { |param| param.to_s.strip }.join(' ')}'"
)
end
end
end
end
2 changes: 1 addition & 1 deletion libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def old_globals(index, application)
"DEPRECATION WARNING: node['deploy']['#{application}']['#{index}'] is deprecated and will be removed. " \
"Please use node['deploy']['#{application}']['global']['#{index}'] instead."
Chef::Log.warn(message)
STDERR.puts(message)
warn(message)
node['deploy'][application][index.to_s]
end

Expand Down

0 comments on commit 59198b9

Please sign in to comment.