capistrano-runit-sidekiq 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 934d3c3f27deab5e2a015cc7b53ba9aa0f08b57f
4
+ data.tar.gz: f89caff58a55ff5adffc611b9069ea34a500754b
5
+ SHA512:
6
+ metadata.gz: 285b58ff6fd2e6c0c14a3c790b67762c37268c6fe5f842cc607e362a83fec909f426f1521a7288f51cc8c834b2991facfcd0b553ef32e5917845d3653dc79f81
7
+ data.tar.gz: af222c2733da6e1fdd07ea52c9cd602ed50563e509693e170354470787919d9a5a51bb48d78c72a8da16ae85a1f464e689e63474c3817e80842e5627ba6cf475
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-runit-sidekiq.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alexander Simonov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # capistrano-runit-sidekiq
2
+
3
+ Capistrano3 tasks for manage sidekiq via runit supervisor.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-runit-sidekiq'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-runit-sidekiq
18
+
19
+ ## Usage
20
+
21
+ Add this line in `Capfile`:
22
+ ```
23
+ require "capistrano/runit/sidekiq"
24
+ ```
25
+
26
+ ## Tasks
27
+
28
+ * `runit:sidekiq:setup` -- setup sidekiq runit service.
29
+ * `runit:sidekiq:enable` -- enable and autostart service.
30
+ * `runit:sidekiq:disable` -- stop and disable service.
31
+ * `runit:sidekiq:start` -- start service.
32
+ * `runit:sidekiq:stop` -- stop service.
33
+ * `runit:sidekiq:restart` -- restart service.
34
+
35
+ ## Variables
36
+
37
+ * `runit_sidekiq_default_hooks` -- run default hooks for runit sidekiq or not. Default value: `true`.
38
+ * `runit_sidekiq_role` -- Role on where sidekiq will be running. Default value: `:app`
39
+ * `runit_sidekiq_pid` -- Pid file path. Default value: `tmp/sidekiq.pid`
40
+ * `runit_sidekiq_run_template` -- path to ERB template of `run` file. Default value: internal default template (`lib/capistrano/runit/templates/run-puma.erb`).
41
+ * `runit_sidekiq_concurrency` -- number of threads of sidekiq process. Default value: `nil`.
42
+ * `runit_sidekiq_queues` -- array of queue names. Default value: `nil`.
43
+ * `runit_sidekiq_config_path` -- relative path to config file. Default value: `nil`.
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/capistrano-runit/capistrano-runit-sidekiq/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "capistrano-runit-sidekiq"
5
+ spec.version = '0.1.0'
6
+ spec.author = ['Oleksandr Simonov', 'Anton Ageev']
7
+ spec.email = ['alex@simonov.me', 'antage@gmail.com']
8
+ spec.summary = %q{Capistrano3 tasks for manage sidekiq via runit supervisor.}
9
+ spec.description = %q{Capistrano3 tasks for manage sidekiq via runit supervisor.}
10
+ spec.homepage = 'http://capistrano-runit.github.io'
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_runtime_dependency 'capistrano-runit-core', '~> 0.1.0'
17
+ spec.add_development_dependency "bundler", "~> 1.6"
18
+ spec.add_development_dependency "rake"
19
+ end
@@ -0,0 +1,3 @@
1
+ require 'capistrano/runit'
2
+ require 'erb'
3
+ load File.expand_path('../../tasks/sidekiq.rake', __FILE__)
@@ -0,0 +1,147 @@
1
+ include ::Capistrano::Runit
2
+
3
+ namespace :load do
4
+ task :defaults do
5
+ set :runit_sidekiq_run_template, nil
6
+ set :runit_sidekiq_concurrency, nil
7
+ set :runit_sidekiq_pid, -> { 'tmp/pids/sidekiq.pid' }
8
+ set :runit_sidekiq_queues, nil
9
+ set :runiq_sidekiq_config_path, nil
10
+ set :runit_sidekiq_default_hooks, -> { true }
11
+ set :runit_sidekiq_role, -> { :app }
12
+ # Rbenv and RVM integration
13
+ set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(sidekiq sidekiqctl))
14
+ set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(sidekiq sidekiqctl))
15
+ end
16
+ end
17
+
18
+ namespace :deploy do
19
+ before :starting, :runit_check_sidekiq_hooks do
20
+ invoke 'runit:sidekiq:add_default_hooks' if fetch(:runit_sidekiq_default_hooks)
21
+ end
22
+ end
23
+
24
+ namespace :runit do
25
+ namespace :sidekiq do
26
+ # Helpers
27
+
28
+ def sidekiq_enabled_service_dir
29
+ enabled_service_dir_for('sidekid')
30
+ end
31
+
32
+ def sidekiq_service_dir
33
+ service_dir_for('sidekiq')
34
+ end
35
+
36
+ def collect_sidekiq_run_command
37
+ array = []
38
+ collect_default_sidekiq_params(array)
39
+ collect_concurrency_sidekiq_params(array)
40
+ collect_queues_sidekiq_params(array)
41
+ collect_log_sidekiq_param(array)
42
+ collect_pid_sidekiq_param(array)
43
+ collect_config_sidekiq_param(array)
44
+ array.compact.join(' ')
45
+ end
46
+
47
+ def sidekiq_environment
48
+ @sidekiq_environment ||= fetch(:rack_env, fetch(:rails_env, 'production'))
49
+ end
50
+
51
+ def collect_default_sidekiq_params(array)
52
+ array << env_variables
53
+ array << "exec #{SSHKit.config.command_map[:bundle]} exec sidekiq"
54
+ array << "-e #{sidekiq_environment}"
55
+ array << "-g #{fetch(:application)}"
56
+ end
57
+
58
+ def collect_concurrency_sidekiq_params(array)
59
+ concurrency = fetch(:runit_sidekiq_concurrency)
60
+ return unless concurrency
61
+ array << "-c #{concurrency}"
62
+ end
63
+
64
+ def collect_queues_sidekiq_params(array)
65
+ queues = fetch(:runit_sidekiq_queues)
66
+ if queues && queues.is_a?(::Array)
67
+ queues.map do |q|
68
+ array << "-q #{q}" if q.is_a?(::String)
69
+ end
70
+ end
71
+ end
72
+
73
+ def collect_config_sidekiq_param(array)
74
+ if (config_path = fetch(:runiq_sidekiq_config_path))
75
+ array << "-C #{config_path}"
76
+ end
77
+ end
78
+
79
+ def collect_log_sidekiq_param(array)
80
+ array << "-L #{File.join(current_path, 'log', "sidekiq.#{sidekiq_environment}.log")}"
81
+ end
82
+
83
+ def collect_pid_sidekiq_param(array)
84
+ array << "-P #{pid_full_path(fetch(:runit_sidekiq_pid))}"
85
+ end
86
+
87
+ task :add_default_hooks do
88
+ after 'deploy:check', 'runit:sidekiq:check'
89
+ after 'deploy:starting', 'runit:sidekiq:quiet'
90
+ after 'deploy:updated', 'runit:sidekiq:stop'
91
+ after 'deploy:reverted', 'runit:sidekiq:stop'
92
+ after 'deploy:published', 'runit:sidekiq:start'
93
+ end
94
+
95
+ task :check do
96
+ check_service('sidekiq')
97
+ end
98
+
99
+ desc 'Setup sidekiq runit service'
100
+ task :setup do
101
+ setup_service('sidekiq', collect_sidekiq_run_command)
102
+ end
103
+
104
+ desc 'Enable sidekiq runit service'
105
+ task :enable do
106
+ enable_service('sidekiq')
107
+ end
108
+
109
+ desc 'Disable sidekiq runit service'
110
+ task :disable do
111
+ disable_service('sidekiq')
112
+ end
113
+
114
+ desc 'Start sidekiq runit service'
115
+ task :start do
116
+ start_service('sidekiq')
117
+ end
118
+
119
+ desc 'Stop sidekiq runit service'
120
+ task :stop do
121
+ stop_service('sidekiq')
122
+ end
123
+
124
+ desc 'Restart sidekiq runit service'
125
+ task :restart do
126
+ restart_service('sidekiq')
127
+ end
128
+
129
+ desc 'Quiet sidekiq (stop accepting new work)'
130
+ task :quiet do
131
+ pid_file = pid_full_path(fetch(:runit_sidekiq_pid))
132
+ on roles fetch(:runit_sidekiq_role) do
133
+ if test "[ -f #{pid_file} ]" && test("kill -0 $( cat #{pid_file})")
134
+ within current_path do
135
+ execute :bundle, :exec, :sidekiqctl, 'quiet', "#{pid_file}"
136
+ end
137
+ else
138
+ info 'Sidekiq is not running'
139
+ if test("[ -f #{pid_file}) ]")
140
+ info 'Removing broken pid file'
141
+ execute :rm, '-f', pid_file
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
File without changes
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-runit-sidekiq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oleksandr Simonov
8
+ - Anton Ageev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano-runit-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.1.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.1.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.6'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.6'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Capistrano3 tasks for manage sidekiq via runit supervisor.
57
+ email:
58
+ - alex@simonov.me
59
+ - antage@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - capistrano-runit-sidekiq.gemspec
70
+ - lib/capistrano-runit-sidekiq.rb
71
+ - lib/capistrano/runit/sidekiq.rb
72
+ - lib/capistrano/tasks/sidekiq.rake
73
+ homepage: http://capistrano-runit.github.io
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Capistrano3 tasks for manage sidekiq via runit supervisor.
97
+ test_files: []