capistrano-sidekiq 2.0.0.beta4 → 2.0.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c60b9de8a0a367ebba98dad3f99cbf3cbee2cc975a42cbe56ff35a0785ee964
4
- data.tar.gz: e8e4dfed5f061db2fa453215df32293469f9bffa6bc9ff0fa1917cef45b31765
3
+ metadata.gz: 50c54a8decaa51b559addb7e9c1d5bfcbdc474cbac2d11054d1cfdc7a8753b1f
4
+ data.tar.gz: c7b60c5cdb1a19d3131ab83c2a6c2e1c54ddf51f9349969f1e3aac26b83de370
5
5
  SHA512:
6
- metadata.gz: 50b2da50e06404fcd6298d1be4a0f1df560e519c990ed9a92ae5feff1a90addfc359b91e0f17fa9d5032621d8648f91bd2c4b6a36ebac86cdfd014ee2bf67094
7
- data.tar.gz: 4892c095fa04edddea3474e974a95dcb219490b26950a82793035471b84e362527cd45988cf945279c4118ef768c56fb471d94ec7f729e80129f4a5342e9f716
6
+ metadata.gz: bb67be5724197a7499c41381fccf9f70db21a245957554a3a9a31f4d296c8bcb44a397db1e89cc1ac2116a804da924157a838e0a4958371d25d1cf905ef6f836
7
+ data.tar.gz: 773d1e88acaae73ed7c62cd3f49c038207d1cf124672fca77f7c7737320bdd037400f573d68edc64aa7f7045c44311a04d570dfd6aaea93dd487636c592be4d9
@@ -1,3 +1,3 @@
1
1
  module Capistrano
2
- SidekiqVERSION = '2.0.0.beta4'
2
+ SidekiqVERSION = '2.0.0.beta5'
3
3
  end
@@ -113,7 +113,7 @@ namespace :sidekiq do
113
113
  backend.execute :sudo, :mv, "/tmp/#{fetch :sidekiq_service_unit_name}.service", "#{systemd_path}/#{fetch :sidekiq_service_unit_name}.service"
114
114
  backend.execute :sudo, :systemctl, "daemon-reload"
115
115
  else
116
- backend.execute :sudo, :mv, "/tmp/#{fetch :sidekiq_service_unit_name}.service", "#{systemd_path}/#{fetch :sidekiq_service_unit_name}.service"
116
+ backend.execute :mv, "/tmp/#{fetch :sidekiq_service_unit_name}.service", "#{systemd_path}/#{fetch :sidekiq_service_unit_name}.service"
117
117
  backend.execute :systemctl, "--user", "daemon-reload"
118
118
  end
119
119
  end
@@ -1,3 +1,5 @@
1
+ git_plugin = self
2
+
1
3
  namespace :sidekiq do
2
4
  desc 'Quiet sidekiq (stop fetching new tasks from Redis)'
3
5
  task :quiet do
@@ -26,6 +28,74 @@ namespace :sidekiq do
26
28
  end
27
29
  end
28
30
 
31
+ desc 'Install upstart sidekiq service'
32
+ task :install do
33
+ on roles fetch(:sidekiq_roles) do |role|
34
+ git_plugin.switch_user(role) do
35
+ git_plugin.create_upstart_template
36
+ end
37
+ end
38
+ end
39
+
40
+ desc 'UnInstall upstart sidekiq service'
41
+ task :uninstall do
42
+ on roles fetch(:sidekiq_roles) do |role|
43
+ git_plugin.switch_user(role) do
44
+ execute :rm, '-f', File.join(fetch(:service_unit_path, fetch_upstart_unit_path), fetch(:sidekiq_service_unit_name))
45
+ end
46
+ end
47
+ end
48
+
49
+ desc 'Generate service_locally'
50
+ task :generate_service_locally do
51
+ run_locally do
52
+ File.write('sidekiq.conf', git_plugin.compiled_template)
53
+ end
54
+ end
55
+
56
+ def fetch_upstart_unit_path
57
+ if fetch(:sidekiq_service_unit_user) == :system
58
+ # if the path is not standard `set :service_unit_path`
59
+ "/etc/init"
60
+ else
61
+ home_dir = backend.capture :pwd
62
+ File.join(home_dir, '.config', 'upstart')
63
+ end
64
+ end
65
+
66
+ def compiled_template
67
+ search_paths = [
68
+ File.expand_path(
69
+ File.join(*%w[.. .. .. generators capistrano sidekiq upstart templates sidekiq.conf.erb]),
70
+ __FILE__
71
+ ),
72
+ ]
73
+ template_path = search_paths.detect { |path| File.file?(path) }
74
+ template = File.read(template_path)
75
+ ERB.new(template).result(binding)
76
+ end
77
+
78
+ def create_upstart_template
79
+ ctemplate = compiled_template
80
+ upstart_path = fetch(:service_unit_path, fetch_upstart_unit_path)
81
+
82
+ if fetch(:sidekiq_service_unit_user) != :system
83
+ backend.execute :mkdir, "-p", upstart_path
84
+ end
85
+ conf_filename = "#{fetch :sidekiq_service_unit_name}.conf"
86
+ backend.upload!(
87
+ StringIO.new(ctemplate),
88
+ "/tmp/#{conf_filename}"
89
+ )
90
+ if fetch(:sidekiq_service_unit_user) == :system
91
+ backend.execute :sudo, :mv, "/tmp/#{conf_filename}", "#{upstart_path}/#{conf_filename}"
92
+ backend.execute :sudo, :initctl, 'reload-configuration'
93
+ else
94
+ backend.execute :sudo, :mv, "/tmp/#{conf_filename}", "#{upstart_path}/#{conf_filename}"
95
+ #backend.execute :sudo, :initctl, 'reload-configuration' #TODO
96
+ end
97
+ end
98
+
29
99
  def switch_user(role)
30
100
  su_user = sidekiq_user(role)
31
101
  if su_user == role.user
@@ -37,11 +107,38 @@ namespace :sidekiq do
37
107
  end
38
108
  end
39
109
 
40
- def sidekiq_user(role)
41
- properties = role.properties
42
- properties.fetch(:sidekiq_user) || # local property for sidekiq only
110
+ def sidekiq_user(role = nil)
111
+ if role.nil?
112
+ fetch(:sidekiq_user)
113
+ else
114
+ properties = role.properties
115
+ properties.fetch(:sidekiq_user) || # local property for sidekiq only
43
116
  fetch(:sidekiq_user) ||
44
117
  properties.fetch(:run_as) || # global property across multiple capistrano gems
45
118
  role.user
119
+ end
120
+ end
121
+
122
+ def num_workers
123
+ fetch(:sidekiq_upstart_num_workers, nil)
124
+ end
125
+
126
+ def sidekiq_config
127
+ if fetch(:sidekiq_config)
128
+ "--config #{fetch(:sidekiq_config)}"
129
+ end
130
+ end
131
+
132
+ def sidekiq_concurrency
133
+ if fetch(:sidekiq_concurrency)
134
+ "--concurrency #{fetch(:sidekiq_concurrency)}"
135
+ end
46
136
  end
137
+
138
+ def sidekiq_queues
139
+ Array(fetch(:sidekiq_queue)).map do |queue|
140
+ "--queue #{queue}"
141
+ end.join(' ')
142
+ end
143
+
47
144
  end
@@ -5,7 +5,7 @@ After=syslog.target network.target
5
5
  [Service]
6
6
  Type=simple
7
7
  WorkingDirectory=<%= File.join(fetch(:deploy_to), 'current') %>
8
- ExecStart=<%= SSHKit.config.command_map[:bundler] %> exec sidekiq -e <%= fetch(:sidekiq_env) %>
8
+ ExecStart=<%= SSHKit.config.command_map[:bundle] %> exec sidekiq -e <%= fetch(:sidekiq_env) %>
9
9
  ExecReload=/bin/kill -TSTP $MAINPID
10
10
  ExecStop=/bin/kill -TERM $MAINPID
11
11
  <%="StandardOutput=append:#{fetch(:sidekiq_log)}" if fetch(:sidekiq_log) %>
@@ -0,0 +1,78 @@
1
+ # /etc/init/sidekiq.conf - Sidekiq config | https://github.com/mperham/sidekiq/blob/master/examples/upstart/sidekiq.conf
2
+
3
+ # This example config should work with Ubuntu 12.04+. It
4
+ # allows you to manage multiple Sidekiq instances with
5
+ # Upstart, Ubuntu's native service management tool.
6
+ #
7
+ # See workers.conf for how to manage all Sidekiq instances at once.
8
+ #
9
+ # Save this config as /etc/init/sidekiq.conf then manage sidekiq with:
10
+ # sudo start <%= fetch(:sidekiq_service_unit_name) %> index=0
11
+ # sudo stop <%= fetch(:sidekiq_service_unit_name) %> index=0
12
+ # sudo status <%= fetch(:sidekiq_service_unit_name) %> index=0
13
+ #
14
+ # Hack Upstart's reload command to 'quiet' Sidekiq:
15
+ #
16
+ # sudo reload <%= fetch(:sidekiq_service_unit_name) %> index=0
17
+ #
18
+ # or use the service command:
19
+ # sudo service <%= fetch(:sidekiq_service_unit_name) %> {start,stop,restart,status}
20
+ #
21
+
22
+ description "Sidekiq for <%= "#{fetch(:application)} (#{fetch(:stage)})" %>"
23
+
24
+ # This script is not meant to start on bootup, workers.conf
25
+ # will start all sidekiq instances explicitly when it starts.
26
+ #start on runlevel [2345]
27
+ #stop on runlevel [06]
28
+ <% if sidekiq_user %>
29
+
30
+ # change to match your deployment user
31
+ setuid <%= sidekiq_user %>
32
+ setgid <%= sidekiq_user %>
33
+ env HOME=/home/<%= sidekiq_user %>
34
+ <% end %>
35
+
36
+ # Greatly reduce Ruby memory fragmentation and heap usage
37
+ # https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/
38
+ env MALLOC_ARENA_MAX=2
39
+
40
+ respawn
41
+ respawn limit 3 30
42
+
43
+ # TERM is used when stopping sidekiq. Without declaring these as
44
+ # normal exit codes, it just respawns.
45
+ normal exit 0 TERM
46
+
47
+ # Older versions of Upstart might not support the reload command and need
48
+ # this commented out.
49
+ reload signal TSTP
50
+
51
+ # Upstart waits 5 seconds by default to kill a process. Increase timeout to
52
+ # give sidekiq process enough time to exit.
53
+ kill timeout 30
54
+ <% if num_workers %>
55
+
56
+ instance $index
57
+ <% end %>
58
+ script
59
+ # this script runs in /bin/sh by default
60
+ # respawn as bash so we can source in rbenv
61
+ exec /bin/bash <<'EOT'
62
+ # Pick your poison :) Or none if you're using a system wide installed Ruby.
63
+ # rbenv
64
+ # source /home/apps/.bash_profile
65
+ # OR
66
+ # source /home/apps/.profile
67
+ # OR system:
68
+ # source /etc/profile.d/rbenv.sh
69
+ #
70
+ # rvm
71
+ # source /home/apps/.rvm/scripts/rvm
72
+
73
+ # Logs out to /var/log/upstart/<%= fetch(:sidekiq_service_unit_name) %>.log by default
74
+
75
+ cd <%= File.join(fetch(:deploy_to), 'current') %>
76
+ exec <%= SSHKit.config.command_map[:bundle] %> exec sidekiq -e <%= fetch(:sidekiq_env) %> <%= sidekiq_config %> <%= sidekiq_concurrency %> <%= sidekiq_queues %>
77
+ EOT
78
+ end script
@@ -0,0 +1,37 @@
1
+ # /etc/init/workers.conf - manage a set of Sidekiqs | https://github.com/mperham/sidekiq/blob/master/examples/upstart/workers.conf
2
+
3
+ # This example config should work with Ubuntu 14.10 and below It
4
+ # allows you to manage multiple Sidekiq instances with
5
+ # Upstart, Ubuntu's native service management tool.
6
+ #
7
+ # See sidekiq.conf for how to manage a single Sidekiq instance.
8
+ #
9
+ # Use "stop workers" to stop all Sidekiq instances.
10
+ # Use "start workers" to start all instances.
11
+ # Use "restart workers" to restart all instances.
12
+ # Crazy, right?
13
+ #
14
+
15
+ description "manages the set of sidekiq processes"
16
+
17
+ # This starts upon bootup and stops on shutdown
18
+ start on runlevel [2345]
19
+ stop on runlevel [06]
20
+
21
+ # Set this to the number of Sidekiq processes you want
22
+ # to run on this machine
23
+ env NUM_WORKERS=2
24
+
25
+ pre-start script
26
+ for i in `seq 1 ${NUM_WORKERS}`
27
+ do
28
+ start sidekiq index=$i
29
+ done
30
+ end script
31
+
32
+ post-stop script
33
+ for i in `seq 1 ${NUM_WORKERS}`
34
+ do
35
+ stop sidekiq index=$i
36
+ done
37
+ end script
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta4
4
+ version: 2.0.0.beta5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-08 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -81,6 +81,8 @@ files:
81
81
  - lib/generators/capistrano/sidekiq/monit/template_generator.rb
82
82
  - lib/generators/capistrano/sidekiq/monit/templates/sidekiq_monit.conf.erb
83
83
  - lib/generators/capistrano/sidekiq/systemd/templates/sidekiq.service.capistrano.erb
84
+ - lib/generators/capistrano/sidekiq/upstart/templates/sidekiq.conf.erb
85
+ - lib/generators/capistrano/sidekiq/upstart/templates/workers.conf.erb
84
86
  homepage: https://github.com/seuros/capistrano-sidekiq
85
87
  licenses:
86
88
  - LGPL-3.0