capistrano-delayed_job 0.0.10 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +5 -4
- data/Gemfile.lock +64 -51
- data/LICENSE +1 -1
- data/README.md +17 -2
- data/Rakefile +14 -12
- data/VERSION +1 -1
- data/capistrano-delayed_job.gemspec +28 -21
- data/lib/capistrano/delayed_job.rb +6 -4
- data/lib/capistrano/helpers/delayed_job/monit.rb +38 -0
- data/lib/capistrano/helpers/delayed_job/runit.rb +28 -0
- data/lib/capistrano/helpers/delayed_job/template_paths.rb +16 -0
- data/lib/capistrano/tasks/config.rake +41 -0
- data/lib/capistrano/tasks/monit.rake +81 -0
- data/lib/capistrano/tasks/runit.rake +149 -0
- data/templates/monit/delayed_job.conf.erb +14 -13
- data/templates/runit/finish.erb +14 -13
- data/templates/runit/log/run.erb +9 -0
- data/templates/runit/run.erb +5 -4
- metadata +45 -41
- data/lib/capistrano/delayed_job/config.rb +0 -35
- data/lib/capistrano/delayed_job/monit.rb +0 -71
- data/lib/capistrano/delayed_job/runit.rb +0 -78
- data/templates/runit/log-run.erb +0 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2b95413e5274f5875c7b1f3e298018d3bb8cd8f9
|
4
|
+
data.tar.gz: 0d3b77d3f0a09e7c12d3e885eb0cc173ae23825f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 158f213b44956c7b7be5e5852cdd98a5f1da1e144e6acf96f20e88b0d4efbe508731d4a8f3f8aa871ae1de82d2721aeb4220ad99c7f8fc93a3fdfac8a070d6f2
|
7
|
+
data.tar.gz: 5a7d97214d8b3ca2bf39732712c8348a606ef6afacd45faec4192b48496c3b61c0da4b3e15d6d6161db902b359b5e1becd848a13536dce7d25b18fe6c69b9d11
|
data/Gemfile
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
gem
|
4
|
-
gem '
|
3
|
+
gem 'capistrano', '~> 3.4'
|
4
|
+
gem 'activesupport', '>= 3.0'
|
5
|
+
gem 'capistrano-monit_runit', '~> 3.0.1'
|
5
6
|
|
6
7
|
group :development do
|
7
|
-
gem
|
8
|
-
gem
|
8
|
+
gem 'bundler', '~> 1.7'
|
9
|
+
gem 'jeweler', '~> 2.0'
|
9
10
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,69 +1,82 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
4
|
+
activesupport (4.2.0)
|
5
|
+
i18n (~> 0.7)
|
6
|
+
json (~> 1.7, >= 1.7.7)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
9
|
+
tzinfo (~> 1.1)
|
10
|
+
addressable (2.3.7)
|
5
11
|
builder (3.2.2)
|
6
|
-
capistrano (
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
capistrano (3.4.0)
|
13
|
+
i18n
|
14
|
+
rake (>= 10.0.0)
|
15
|
+
sshkit (~> 1.3)
|
16
|
+
capistrano-monit_runit (3.0.1)
|
17
|
+
activesupport (>= 3.0)
|
18
|
+
capistrano (~> 3.4)
|
19
|
+
colorize (0.7.5)
|
20
|
+
descendants_tracker (0.0.4)
|
21
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
22
|
+
faraday (0.9.1)
|
23
|
+
multipart-post (>= 1.2, < 3)
|
24
|
+
git (1.2.9.1)
|
25
|
+
github_api (0.12.3)
|
26
|
+
addressable (~> 2.3)
|
27
|
+
descendants_tracker (~> 0.0.4)
|
28
|
+
faraday (~> 0.8, < 0.10)
|
29
|
+
hashie (>= 3.3)
|
30
|
+
multi_json (>= 1.7.5, < 2.0)
|
31
|
+
nokogiri (~> 1.6.3)
|
23
32
|
oauth2
|
24
|
-
hashie (
|
25
|
-
highline (1.
|
26
|
-
|
27
|
-
jeweler (
|
33
|
+
hashie (3.4.0)
|
34
|
+
highline (1.7.1)
|
35
|
+
i18n (0.7.0)
|
36
|
+
jeweler (2.0.1)
|
28
37
|
builder
|
29
|
-
bundler (
|
38
|
+
bundler (>= 1.0)
|
30
39
|
git (>= 1.2.5)
|
31
|
-
github_api
|
40
|
+
github_api
|
32
41
|
highline (>= 1.6.15)
|
33
|
-
nokogiri (
|
42
|
+
nokogiri (>= 1.5.10)
|
34
43
|
rake
|
35
44
|
rdoc
|
36
|
-
json (1.8.
|
37
|
-
jwt (
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
json (1.8.2)
|
46
|
+
jwt (1.4.1)
|
47
|
+
mini_portile (0.6.2)
|
48
|
+
minitest (5.5.1)
|
49
|
+
multi_json (1.11.0)
|
50
|
+
multi_xml (0.5.5)
|
51
|
+
multipart-post (2.0.0)
|
52
|
+
net-scp (1.2.1)
|
43
53
|
net-ssh (>= 2.6.5)
|
44
|
-
net-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
faraday (~> 0.8)
|
52
|
-
httpauth (~> 0.2)
|
53
|
-
jwt (~> 0.1.4)
|
54
|
-
multi_json (~> 1.0)
|
54
|
+
net-ssh (2.9.2)
|
55
|
+
nokogiri (1.6.6.2)
|
56
|
+
mini_portile (~> 0.6.0)
|
57
|
+
oauth2 (1.0.0)
|
58
|
+
faraday (>= 0.8, < 0.10)
|
59
|
+
jwt (~> 1.0)
|
60
|
+
multi_json (~> 1.3)
|
55
61
|
multi_xml (~> 0.5)
|
56
62
|
rack (~> 1.2)
|
57
|
-
rack (1.
|
58
|
-
rake (10.
|
59
|
-
rdoc (4.0
|
60
|
-
|
63
|
+
rack (1.6.0)
|
64
|
+
rake (10.4.2)
|
65
|
+
rdoc (4.2.0)
|
66
|
+
sshkit (1.7.1)
|
67
|
+
colorize (>= 0.7.0)
|
68
|
+
net-scp (>= 1.1.2)
|
69
|
+
net-ssh (>= 2.8.0)
|
70
|
+
thread_safe (0.3.5)
|
71
|
+
tzinfo (1.2.2)
|
72
|
+
thread_safe (~> 0.1)
|
61
73
|
|
62
74
|
PLATFORMS
|
63
75
|
ruby
|
64
76
|
|
65
77
|
DEPENDENCIES
|
66
|
-
|
67
|
-
|
68
|
-
capistrano
|
69
|
-
|
78
|
+
activesupport (>= 3.0)
|
79
|
+
bundler (~> 1.7)
|
80
|
+
capistrano (~> 3.4)
|
81
|
+
capistrano-monit_runit (~> 3.0.1)
|
82
|
+
jeweler (~> 2.0)
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,20 +2,35 @@
|
|
2
2
|
|
3
3
|
This gem provides recipes for [Delayed Job](https://github.com/collectiveidea/delayed_job) to setup [runit](smarden.org/runit/) and [monit](http://mmonit.com/monit)
|
4
4
|
|
5
|
+
## Versioning
|
6
|
+
|
7
|
+
Use 3.x for capistrano 3
|
8
|
+
|
9
|
+
For capistrano2, see the capistrano2 branch (will not be updated)
|
10
|
+
|
5
11
|
## Usage
|
6
12
|
|
7
13
|
Add it to your Gemfile without requiring it
|
8
14
|
|
9
15
|
```ruby
|
10
|
-
gem 'capistrano-delayed_job', :
|
16
|
+
gem 'capistrano-delayed_job', require: false
|
11
17
|
```
|
12
18
|
|
13
|
-
|
19
|
+
Now run ```bundle install```
|
20
|
+
|
21
|
+
Add this to your Capfile:
|
14
22
|
|
15
23
|
```ruby
|
16
24
|
require 'capistrano/delayed_job'
|
17
25
|
```
|
18
26
|
|
27
|
+
Create a new file in in /etc/sudoers.d/ and add the output of the following commands:
|
28
|
+
|
29
|
+
```
|
30
|
+
cap production runit:sudoers
|
31
|
+
cap production monit:sudoers
|
32
|
+
```
|
33
|
+
|
19
34
|
### Monit
|
20
35
|
|
21
36
|
```
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
Bundler.setup(:default, :development)
|
7
7
|
rescue Bundler::BundlerError => e
|
8
8
|
$stderr.puts e.message
|
9
|
-
$stderr.puts
|
9
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
10
10
|
exit e.status_code
|
11
11
|
end
|
12
12
|
require 'rake'
|
@@ -14,24 +14,26 @@ require 'rake'
|
|
14
14
|
require 'jeweler'
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name =
|
18
|
-
gem.homepage =
|
19
|
-
gem.license =
|
20
|
-
gem.summary =
|
21
|
-
gem.description =
|
22
|
-
gem.email =
|
23
|
-
gem.authors = [
|
24
|
-
gem.files.exclude
|
17
|
+
gem.name = 'capistrano-delayed_job'
|
18
|
+
gem.homepage = 'https://github.com/leifcr/capistrano-delayed_job'
|
19
|
+
gem.license = 'MIT'
|
20
|
+
gem.summary = 'Capistrano recipes for Delayed Job using runit and monit'
|
21
|
+
gem.description = 'Capistrano recipes for Delayed Job using runit and monit.'
|
22
|
+
gem.email = 'leifcr@gmail.com'
|
23
|
+
gem.authors = ['Leif Ringstad']
|
24
|
+
gem.files.exclude '.ruby-*'
|
25
|
+
gem.files.exclude '*.sublime-project'
|
26
|
+
gem.files.exclude '.rubocop.yml'
|
25
27
|
# dependencies defined in Gemfile
|
26
28
|
end
|
27
29
|
Jeweler::RubygemsDotOrgTasks.new
|
28
30
|
|
29
31
|
# require 'rdoc/task'
|
30
32
|
# Rake::RDocTask.new do |rdoc|
|
31
|
-
# version = File.exist?('VERSION') ? File.read('VERSION') :
|
33
|
+
# version = File.exist?('VERSION') ? File.read('VERSION') : ''
|
32
34
|
|
33
35
|
# rdoc.rdoc_dir = 'rdoc'
|
34
|
-
# rdoc.title =
|
36
|
+
# rdoc.title = 'capistrano-empty #{version}'
|
35
37
|
# rdoc.rdoc_files.include('README*')
|
36
38
|
# rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
-
# end
|
39
|
+
# end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
3.0.0
|
@@ -2,14 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: capistrano-delayed_job 3.0.0 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "capistrano-delayed_job"
|
8
|
-
s.version = "0.0
|
9
|
+
s.version = "3.0.0"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
11
13
|
s.authors = ["Leif Ringstad"]
|
12
|
-
s.date = "
|
14
|
+
s.date = "2015-03-26"
|
13
15
|
s.description = "Capistrano recipes for Delayed Job using runit and monit."
|
14
16
|
s.email = "leifcr@gmail.com"
|
15
17
|
s.extra_rdoc_files = [
|
@@ -25,39 +27,44 @@ Gem::Specification.new do |s|
|
|
25
27
|
"VERSION",
|
26
28
|
"capistrano-delayed_job.gemspec",
|
27
29
|
"lib/capistrano/delayed_job.rb",
|
28
|
-
"lib/capistrano/delayed_job/
|
29
|
-
"lib/capistrano/delayed_job/
|
30
|
-
"lib/capistrano/delayed_job/
|
30
|
+
"lib/capistrano/helpers/delayed_job/monit.rb",
|
31
|
+
"lib/capistrano/helpers/delayed_job/runit.rb",
|
32
|
+
"lib/capistrano/helpers/delayed_job/template_paths.rb",
|
33
|
+
"lib/capistrano/tasks/config.rake",
|
34
|
+
"lib/capistrano/tasks/monit.rake",
|
35
|
+
"lib/capistrano/tasks/runit.rake",
|
31
36
|
"templates/monit/delayed_job.conf.erb",
|
32
37
|
"templates/runit/finish.erb",
|
33
|
-
"templates/runit/log
|
38
|
+
"templates/runit/log/run.erb",
|
34
39
|
"templates/runit/run.erb"
|
35
40
|
]
|
36
41
|
s.homepage = "https://github.com/leifcr/capistrano-delayed_job"
|
37
42
|
s.licenses = ["MIT"]
|
38
|
-
s.
|
39
|
-
s.rubygems_version = "1.8.25"
|
43
|
+
s.rubygems_version = "2.4.6"
|
40
44
|
s.summary = "Capistrano recipes for Delayed Job using runit and monit"
|
41
45
|
|
42
46
|
if s.respond_to? :specification_version then
|
43
|
-
s.specification_version =
|
47
|
+
s.specification_version = 4
|
44
48
|
|
45
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
-
s.add_runtime_dependency(%q<capistrano>, ["
|
47
|
-
s.add_runtime_dependency(%q<
|
48
|
-
s.
|
49
|
-
s.add_development_dependency(%q<
|
50
|
+
s.add_runtime_dependency(%q<capistrano>, ["~> 3.4"])
|
51
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 3.0"])
|
52
|
+
s.add_runtime_dependency(%q<capistrano-monit_runit>, ["~> 3.0.1"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.7"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
|
50
55
|
else
|
51
|
-
s.add_dependency(%q<capistrano>, ["
|
52
|
-
s.add_dependency(%q<
|
53
|
-
s.add_dependency(%q<
|
54
|
-
s.add_dependency(%q<
|
56
|
+
s.add_dependency(%q<capistrano>, ["~> 3.4"])
|
57
|
+
s.add_dependency(%q<activesupport>, [">= 3.0"])
|
58
|
+
s.add_dependency(%q<capistrano-monit_runit>, ["~> 3.0.1"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.7"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
55
61
|
end
|
56
62
|
else
|
57
|
-
s.add_dependency(%q<capistrano>, ["
|
58
|
-
s.add_dependency(%q<
|
59
|
-
s.add_dependency(%q<
|
60
|
-
s.add_dependency(%q<
|
63
|
+
s.add_dependency(%q<capistrano>, ["~> 3.4"])
|
64
|
+
s.add_dependency(%q<activesupport>, [">= 3.0"])
|
65
|
+
s.add_dependency(%q<capistrano-monit_runit>, ["~> 3.0.1"])
|
66
|
+
s.add_dependency(%q<bundler>, ["~> 1.7"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
61
68
|
end
|
62
69
|
end
|
63
70
|
|
@@ -2,10 +2,12 @@ def try_require(library)
|
|
2
2
|
begin
|
3
3
|
require "#{library}"
|
4
4
|
rescue LoadError => e
|
5
|
-
puts "Capistrano-
|
5
|
+
puts "Capistrano-DelayedJob: Cannot load library: #{library} Error: #{e}"
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
try_require 'capistrano/
|
10
|
-
try_require 'capistrano/
|
11
|
-
|
9
|
+
try_require 'capistrano/monit'
|
10
|
+
try_require 'capistrano/runit'
|
11
|
+
load File.expand_path('../tasks/config.rake', __FILE__)
|
12
|
+
load File.expand_path('../tasks/monit.rake', __FILE__)
|
13
|
+
load File.expand_path('../tasks/runit.rake', __FILE__)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Helpers
|
3
|
+
module DelayedJob
|
4
|
+
##
|
5
|
+
# Module Monit provides helpers for Monit/Puma combination
|
6
|
+
##
|
7
|
+
module Monit
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def delayed_job_pid_file(worker_number)
|
11
|
+
service_pid("#{fetch(:delayed_job_runit_base_service_name)}_#{worker_number}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def delayed_job_monit_service_name(worker_number)
|
15
|
+
"#{fetch(:delayed_job_monit_base_service_name)}_#{worker_number}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def delayed_job_monit_start_command(worker_number)
|
19
|
+
"/bin/bash -c '[ ! -h #{runit_service_path(delayed_job_monit_service_name(worker_number))}/run ] || /usr/bin/sv start #{runit_service_path(delayed_job_monit_service_name(worker_number))}'" # rubocop:disable Metrics/LineLength
|
20
|
+
end
|
21
|
+
|
22
|
+
def delayed_job_monit_stop_command(worker_number)
|
23
|
+
# Give delayed job 60 seconds to finish any jobs it's currently handling.
|
24
|
+
# (Tasks that are longer than 60 seconds should be split!)
|
25
|
+
"/usr/bin/sv -w 60 force-stop #{runit_service_path(delayed_job_monit_service_name(worker_number))}" # rubocop:disable Metrics/LineLength
|
26
|
+
end
|
27
|
+
|
28
|
+
def available_configuration_with_path(worker_number)
|
29
|
+
File.join(fetch(:monit_available_path), "#{fetch(:delayed_job_runit_base_service_name)}_#{worker_number}.conf")
|
30
|
+
end
|
31
|
+
|
32
|
+
def available_configuration_file(worker_number)
|
33
|
+
"#{fetch(:delayed_job_runit_base_service_name)}_#{worker_number}.conf"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Helpers
|
3
|
+
module DelayedJob
|
4
|
+
##
|
5
|
+
# Module Monit provides helpers for Monit/Puma combination
|
6
|
+
##
|
7
|
+
module Runit
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def delayed_job_runit_service_name(worker_number)
|
11
|
+
"#{fetch(:delayed_job_runit_base_service_name)}_#{worker_number}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def delayed_job_log_path(worker_number)
|
15
|
+
runit_var_log_service_single_service_path(delayed_job_runit_service_name(worker_number))
|
16
|
+
end
|
17
|
+
|
18
|
+
def available_configuration_with_path(worker_number)
|
19
|
+
File.join(fetch(:monit_available_path), "#{fetch(:delayed_job_runit_service_name)}_#{worker_number}.conf")
|
20
|
+
end
|
21
|
+
|
22
|
+
def available_configuration_file(worker_number)
|
23
|
+
"#{fetch(:delayed_job_runit_service_name)}_#{worker_number}.conf"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Helpers
|
3
|
+
module DelayedJob
|
4
|
+
##
|
5
|
+
# Paths for templates
|
6
|
+
#
|
7
|
+
module TemplatePaths
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def template_base_path
|
11
|
+
File.expand_path(File.join(File.dirname(__FILE__), '../../../../templates'))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'capistrano/helpers/base'
|
2
|
+
require 'capistrano/helpers/delayed_job/template_paths'
|
3
|
+
include Capistrano::Helpers::Base
|
4
|
+
|
5
|
+
namespace :load do
|
6
|
+
task :defaults do
|
7
|
+
set :delayed_job_runit_base_service_name, 'delayed_job'
|
8
|
+
|
9
|
+
# The number of workers to run
|
10
|
+
# Will create X number of runit services/monit monitors.
|
11
|
+
# Remember to purge/remove config before changing this value down
|
12
|
+
# Default to 2 workers
|
13
|
+
set :delayed_job_workers, 2
|
14
|
+
|
15
|
+
# The binary to trigger delayed job
|
16
|
+
set :delayed_job_bin, 'bundle exec rake jobs:work'
|
17
|
+
|
18
|
+
# runit defaults
|
19
|
+
set :delayed_job_restart_interval, proc { fetch(:runit_restart_interval) }
|
20
|
+
set :delayed_job_restart_count, proc { fetch(:runit_restart_count) }
|
21
|
+
set :delayed_job_autorestart_clear_interval, proc { fetch(:runit_autorestart_clear_interval) }
|
22
|
+
|
23
|
+
# runit templates
|
24
|
+
set :delayed_job_runit_run_template, File.join(Capistrano::Helpers::DelayedJob::TemplatePaths.template_base_path, 'runit', 'run.erb') # rubocop:disable Metrics/LineLength
|
25
|
+
set :delayed_job_runit_finish_template, File.join(Capistrano::Helpers::DelayedJob::TemplatePaths.template_base_path, 'runit', 'finish.erb') # rubocop:disable Metrics/LineLength
|
26
|
+
set :delayed_job_runit_log_run_template, File.join(Capistrano::Helpers::DelayedJob::TemplatePaths.template_base_path, 'runit', 'log', 'run.erb') # rubocop:disable Metrics/LineLength
|
27
|
+
|
28
|
+
# monit configuration
|
29
|
+
set :delayed_job_monit_base_service_name, proc { "#{user_app_env_underscore}_delayed_job" }
|
30
|
+
# Each worker would be likely to use at least 60-70mb ram for an app with many gems
|
31
|
+
set :delayed_job_monit_memory_alert_threshold, '100.0 MB for 2 cycles'
|
32
|
+
# Give the delayed_job_workers some headroom
|
33
|
+
set :delayed_job_monit_memory_restart_threshold, '150.0 MB for 3 cycles'
|
34
|
+
set :delayed_job_monit_cpu_alert_threshold, '90% for 2 cycles'
|
35
|
+
set :delayed_job_monit_cpu_restart_threshold, '95% for 5 cycles'
|
36
|
+
|
37
|
+
set :delayed_job_monit_config_template, File.join(Capistrano::Helpers::DelayedJob::TemplatePaths.template_base_path, 'monit', 'delayed_job.conf.erb') # rubocop:disable Metrics/LineLength
|
38
|
+
|
39
|
+
set :monit_application_delayed_job_group_name, proc { "#{user_app_env_underscore}_delayed_job" }
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'capistrano/dsl/base_paths'
|
2
|
+
require 'capistrano/dsl/runit_paths'
|
3
|
+
require 'capistrano/helpers/base'
|
4
|
+
require 'capistrano/helpers/monit'
|
5
|
+
require 'capistrano/helpers/delayed_job/monit'
|
6
|
+
include Capistrano::DSL::BasePaths
|
7
|
+
include Capistrano::DSL::RunitPaths
|
8
|
+
include Capistrano::Helpers::Base
|
9
|
+
include Capistrano::Helpers::Monit
|
10
|
+
include Capistrano::Helpers::DelayedJob::Monit
|
11
|
+
|
12
|
+
namespace :delayed_job do
|
13
|
+
namespace :monit do
|
14
|
+
desc 'MONIT: Setup Delayed Job service'
|
15
|
+
task :setup do
|
16
|
+
on roles(:app) do |host|
|
17
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
18
|
+
info "MONIT: Uploading configuration for Delayed Job worker #{n} for #{fetch(:application)} on #{host}"
|
19
|
+
# Upload configuration
|
20
|
+
set :tmp_delayed_job_monit_service_name, delayed_job_monit_service_name(n)
|
21
|
+
set :tmp_worker_number, n
|
22
|
+
set :tmp_delayed_job_pid_file, delayed_job_pid_file(n)
|
23
|
+
upload! template_to_s_io(fetch(:delayed_job_monit_config_template)), available_configuration_with_path(n)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'MONIT: Enable services for Delayed Job'
|
29
|
+
task :enable do
|
30
|
+
on roles(:app) do |host|
|
31
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
32
|
+
info "MONIT: Enabling service for Delayed Job worker #{n} for #{fetch(:application)} on #{host}"
|
33
|
+
enable_monitor(available_configuration_file(n))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'MONIT: Disable and Stop services for Delayed Job'
|
39
|
+
task :disable do
|
40
|
+
on roles(:app) do |host|
|
41
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
42
|
+
info "MONIT: Disabling service for Delayed Job worker #{n} for #{fetch(:application)} on #{host}"
|
43
|
+
disable_monitor(available_configuration_file(n))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
%w(start stop restart monitor unmonitor).each do |cmd|
|
49
|
+
desc "MONIT: #{cmd.capitalize} Delayed Job"
|
50
|
+
task cmd.to_sym do
|
51
|
+
on roles(:app) do |host|
|
52
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
53
|
+
info "MONIT: #{cmd} Delayed Job worker #{n} for #{fetch(:application)} on #{host}"
|
54
|
+
command_monit(cmd, available_configuration_file(n))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
desc 'MONIT: Purge Delayed Job configuration'
|
61
|
+
task :purge do
|
62
|
+
on roles(:app) do |host|
|
63
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
64
|
+
info "MONIT: Purging config for Delayed Job worker #{n} for #{fetch(:application)} on #{host}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
after 'monit:setup', 'delayed_job:monit:setup'
|
72
|
+
# after 'delayed_job:monit:setup', 'delayed_job:monit:enable'
|
73
|
+
after 'delayed_job:monit:enable', 'monit:reload'
|
74
|
+
|
75
|
+
before 'delayed_job:monit:disable', 'delayed_job:monit:unmonitor'
|
76
|
+
after 'delayed_job:monit:disable', 'monit:reload'
|
77
|
+
|
78
|
+
# start service after update in case it has not been stopped
|
79
|
+
# This shouldn't be necessary, as monit should pick up a non-running service.
|
80
|
+
# Starting it here might trigger double starting if monit is triggered simultaniously.
|
81
|
+
# after "deploy:update", "delayed_job:monit:start"
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'capistrano/dsl/base_paths'
|
2
|
+
require 'capistrano/dsl/runit_paths'
|
3
|
+
require 'capistrano/helpers/base'
|
4
|
+
require 'capistrano/helpers/runit'
|
5
|
+
require 'capistrano/helpers/delayed_job/runit'
|
6
|
+
|
7
|
+
include Capistrano::DSL::BasePaths
|
8
|
+
include Capistrano::DSL::RunitPaths
|
9
|
+
include Capistrano::Helpers::Base
|
10
|
+
include Capistrano::Helpers::Runit
|
11
|
+
include Capistrano::Helpers::DelayedJob::Runit
|
12
|
+
|
13
|
+
# require 'capistrano/runit'
|
14
|
+
namespace :delayed_job do
|
15
|
+
desc 'Setup Delayed Job configuration'
|
16
|
+
task :setup do
|
17
|
+
on roles(:app) do
|
18
|
+
execute :mkdir, "-p #{fetch(:sockets_path)}" if test("[ ! -d '#{fetch(:sockets_path)}' ]")
|
19
|
+
upload! template_to_s_io(fetch(:puma_config_template)), fetch(:puma_config_file)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
namespace :runit do
|
24
|
+
desc 'Setup Delayed Job runit-service'
|
25
|
+
task :setup do
|
26
|
+
on roles(:app) do
|
27
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
28
|
+
# Create runit config
|
29
|
+
if test("[ ! -d '#{runit_service_path(delayed_job_runit_service_name(n))}' ]")
|
30
|
+
execute :mkdir, "-p '#{runit_service_path(delayed_job_runit_service_name(n))}'"
|
31
|
+
end
|
32
|
+
|
33
|
+
set :tmp_delayed_job_runit_service_name, delayed_job_runit_service_name(n)
|
34
|
+
set :tmp_worker_number, n
|
35
|
+
|
36
|
+
upload! template_to_s_io(fetch(:delayed_job_runit_run_template)), runit_service_run_config_file(delayed_job_runit_service_name(n)) # rubocop:disable Metrics/LineLength
|
37
|
+
upload! template_to_s_io(fetch(:delayed_job_runit_finish_template)), runit_service_finish_config_file(delayed_job_runit_service_name(n)) # rubocop:disable Metrics/LineLength
|
38
|
+
|
39
|
+
# Log scripts for runit service
|
40
|
+
if test("[ ! -d '#{runit_service_log_path(delayed_job_runit_service_name(n))}' ]")
|
41
|
+
execute :mkdir, "-p '#{runit_service_log_path(delayed_job_runit_service_name(n))}'"
|
42
|
+
end
|
43
|
+
|
44
|
+
set :tmp_delayed_job_log_path, delayed_job_log_path(n)
|
45
|
+
|
46
|
+
upload! template_to_s_io(fetch(:delayed_job_runit_log_run_template)), runit_service_log_run_file(delayed_job_runit_service_name(n)) # rubocop:disable Metrics/LineLength
|
47
|
+
|
48
|
+
# Make scripts executable
|
49
|
+
runit_set_executable_files(delayed_job_runit_service_name(n))
|
50
|
+
|
51
|
+
# Create log paths for the service
|
52
|
+
if test("[ ! -d '#{runit_var_log_service_single_service_path(delayed_job_runit_service_name(n))}' ]")
|
53
|
+
execute :mkdir, "-p '#{runit_var_log_service_single_service_path(delayed_job_runit_service_name(n))}'"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Enable Delayed Job runit-services'
|
60
|
+
task :enable do
|
61
|
+
on roles(:app) do
|
62
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
63
|
+
enable_service(delayed_job_runit_service_name(n))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
desc 'Disable Delayed Job runit-services'
|
69
|
+
task :disable do
|
70
|
+
on roles(:app) do
|
71
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
72
|
+
disable_service(delayed_job_runit_service_name(n))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
desc 'Start Delayed Job runit-services'
|
78
|
+
task :start do
|
79
|
+
on roles(:app) do
|
80
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
81
|
+
control_service(delayed_job_runit_service_name(n), 'start')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
desc 'Start Delayed Job runit-services only ONCE (no supervision...)'
|
87
|
+
task :once do
|
88
|
+
on roles(:app) do
|
89
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
90
|
+
control_service(delayed_job_runit_service_name(n), 'once')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
desc 'Stop Delayed Job runit-services'
|
96
|
+
# :on_error => :continue should be added when cap3 equivalent has been figured out
|
97
|
+
task :stop do
|
98
|
+
on roles(:app) do
|
99
|
+
# will wait 45 seconds for delayed job to shut down/finish current jobs, to allow it to
|
100
|
+
# Process ongoing tasks.
|
101
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
102
|
+
begin
|
103
|
+
control_service(delayed_job_runit_service_name(n), 'force-stop', '-w 45')
|
104
|
+
rescue
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
desc 'Quit the Delayed Job runit-services'
|
111
|
+
# :on_error => :continue should be added when cap3 equivalent has been figured out
|
112
|
+
task :quit do
|
113
|
+
on roles(:app) do
|
114
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
115
|
+
control_service(delayed_job_runit_service_name(n), 'quit')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
desc 'Restart Delayed Job runit-services'
|
121
|
+
task :restart do
|
122
|
+
on roles(:app) do
|
123
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
124
|
+
control_service(delayed_job_runit_service_name(n), 'restart')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
desc 'Purge Delayed Job runit configuration'
|
130
|
+
# :on_error => :continue should be added when cap3 equivalent has been figured out
|
131
|
+
task :purge do
|
132
|
+
on roles(:app) do
|
133
|
+
(1..fetch(:delayed_job_workers)).each do |n|
|
134
|
+
disable_service(delayed_job_runit_service_name(n))
|
135
|
+
purge_service(delayed_job_runit_service_name(n))
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
after 'runit:setup', 'delayed_job:runit:setup'
|
143
|
+
|
144
|
+
# enable service after update in case it has been disabled
|
145
|
+
# Service should probably be started as well?
|
146
|
+
after 'deploy:updated', 'delayed_job:runit:enable'
|
147
|
+
# before 'delayed_job:runit:setup', 'delayed_job:flush_sockets'
|
148
|
+
before 'delayed_job:runit:setup', 'delayed_job:setup'
|
149
|
+
before 'delayed_job:runit:quit', 'delayed_job:runit:stop'
|
@@ -1,16 +1,17 @@
|
|
1
|
-
# Monit configuration for
|
2
|
-
#
|
3
|
-
# <%= "#{
|
1
|
+
# Monit configuration for:
|
2
|
+
# Delayed Job worker <%= fetch(:tmp_worker_number) %>
|
3
|
+
# Application: <%= "#{fetch(:application)} running as #{fetch(:user)} in environment #{environment}" %>
|
4
4
|
#
|
5
|
-
# Service name: <%=
|
5
|
+
# Service name: <%= fetch(:tmp_delayed_job_monit_service_name) %>
|
6
6
|
#
|
7
|
-
check process <%=
|
8
|
-
with pidfile <%=
|
9
|
-
start program = "<%=
|
10
|
-
stop program = "<%=
|
11
|
-
<%= "if mem is greater than #{
|
12
|
-
<%= "if mem is greater than #{
|
13
|
-
<%= "if cpu is greater than #{
|
14
|
-
<%= "if cpu is greater than #{
|
7
|
+
check process <%= fetch(:tmp_delayed_job_monit_service_name) %>
|
8
|
+
with pidfile <%= fetch(:tmp_delayed_job_pid_file) %>
|
9
|
+
start program = "<%= delayed_job_monit_start_command(fetch(:tmp_worker_number)) %>"
|
10
|
+
stop program = "<%= delayed_job_monit_stop_command(fetch(:tmp_worker_number)) %>"
|
11
|
+
<%= "if mem is greater than #{fetch(:delayed_job_monit_memory_alert_threshold)} then alert" unless fetch(:delayed_job_monit_memory_alert_threshold).nil? %>
|
12
|
+
<%= "if mem is greater than #{fetch(:delayed_job_monit_memory_restart_threshold)} then restart" unless fetch(:delayed_job_monit_memory_restart_threshold).nil? %>
|
13
|
+
<%= "if cpu is greater than #{fetch(:delayed_job_monit_cpu_alert_threshold)} then alert" unless fetch(:delayed_job_monit_cpu_alert_threshold).nil? %>
|
14
|
+
<%= "if cpu is greater than #{fetch(:delayed_job_monit_cpu_restart_threshold)} then restart" unless fetch(:delayed_job_monit_cpu_restart_threshold).nil? %>
|
15
15
|
|
16
|
-
group <%=
|
16
|
+
group <%= fetch(:monit_application_delayed_job_group_name) %>
|
17
|
+
group <%= fetch(:monit_application_group_name) %>
|
data/templates/runit/finish.erb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
#
|
3
|
+
# Delayed_Job worker <%= fetch(:tmp_worker_number) %> running on <%= fetch(:application) %> running as <%= fetch(:user) %>
|
4
|
+
#
|
3
5
|
# This finish file is originally from:
|
4
6
|
# https://github.com/erwbgy/puppet-runit/blob/fde6006e6d400f0c99b6ff0b1b63094207dc8783/templates/service/finish.erb
|
5
7
|
# Thanks to erwbgy!
|
6
8
|
#
|
7
|
-
# <% c = Capistrano::BaseHelper::get_capistrano_instance %>
|
8
9
|
# Variable name setup
|
9
10
|
<%
|
10
|
-
exit_code = "EXIT_CODE_#{
|
11
|
-
exit_status = "EXIT_STATUS_#{
|
12
|
-
min_auto_restart_interval = "MIN_AUTO_RESTART_INTERVAL_#{
|
13
|
-
max_auto_restart_count = "MAX_AUTO_RESTART_COUNT_#{
|
14
|
-
auto_restart_count_clear_interval = "AUTO_RESTART_COUNT_CLEAR_INTERVAL_#{
|
11
|
+
exit_code = "EXIT_CODE_#{user_app_env_underscore_short_char_safe}_#{fetch(:tmp_delayed_job_runit_service_name)}".upcase
|
12
|
+
exit_status = "EXIT_STATUS_#{user_app_env_underscore_short_char_safe}_#{fetch(:tmp_delayed_job_runit_service_name)}".upcase
|
13
|
+
min_auto_restart_interval = "MIN_AUTO_RESTART_INTERVAL_#{user_app_env_underscore_short_char_safe}_#{fetch(:tmp_delayed_job_runit_service_name)}".upcase
|
14
|
+
max_auto_restart_count = "MAX_AUTO_RESTART_COUNT_#{user_app_env_underscore_short_char_safe}_#{fetch(:tmp_delayed_job_runit_service_name)}".upcase
|
15
|
+
auto_restart_count_clear_interval = "AUTO_RESTART_COUNT_CLEAR_INTERVAL_#{user_app_env_underscore_short_char_safe}_#{fetch(:tmp_delayed_job_runit_service_name)}".upcase
|
15
16
|
%>
|
16
17
|
#
|
17
18
|
# The following variables are set by Runit:
|
@@ -52,14 +53,14 @@ auto_restart_count_clear_interval = "AUTO_RESTART_COUNT_CLEAR_INTERVAL_#{Capistr
|
|
52
53
|
<%= "#{exit_status}" %>=$2
|
53
54
|
|
54
55
|
# The minimum delay (in seconds) between automatic restarts
|
55
|
-
<%= "#{min_auto_restart_interval}" %>=<%=
|
56
|
+
<%= "#{min_auto_restart_interval}" %>=<%= fetch(:delayed_job_restart_interval) %>
|
56
57
|
|
57
58
|
# The maximum number of automatic restarts allowed
|
58
|
-
<%= "#{max_auto_restart_count}" %>=<%=
|
59
|
+
<%= "#{max_auto_restart_count}" %>=<%= fetch(:delayed_job_restart_count) %>
|
59
60
|
|
60
61
|
# Reset the restart count if <%= "#{auto_restart_count_clear_interval}" %> seconds
|
61
62
|
# have elapsed since the last automatic restart.
|
62
|
-
<%= "#{auto_restart_count_clear_interval}" %>=<%=
|
63
|
+
<%= "#{auto_restart_count_clear_interval}" %>=<%= fetch(:delayed_job_autorestart_clear_interval) %>
|
63
64
|
|
64
65
|
export <%= "#{exit_code}" %>
|
65
66
|
export <%= "#{exit_status}" %>
|
@@ -69,7 +70,7 @@ export <%= "#{auto_restart_count_clear_interval }" %>
|
|
69
70
|
|
70
71
|
### Normally no changes should be made after this point
|
71
72
|
|
72
|
-
echo "<%= "User: #{
|
73
|
+
echo "<%= "User: #{fetch(:user)} Application: #{fetch(:application)} Service: #{fetch(:tmp_delayed_job_runit_service_name)}" %> finish; exit code: $<%= "#{exit_code}" %>; exit status: $<%= "#{exit_status}" %>"
|
73
74
|
|
74
75
|
if test $<%= "#{exit_code}" %> -eq 0 -a $<%= "#{exit_status}" %> -eq 0
|
75
76
|
then
|
@@ -92,7 +93,7 @@ echo $NOW > last_finish
|
|
92
93
|
# have elapsed since the last automatic restart.
|
93
94
|
if test $INTERVAL -gt $<%= "#{auto_restart_count_clear_interval}" %>
|
94
95
|
then
|
95
|
-
echo "NOTICE: <%= "User: #{
|
96
|
+
echo "NOTICE: <%= "User: #{fetch(:user)} Application: #{fetch(:application)} Service: #{fetch(:tmp_delayed_job_runit_service_name)}" %>"
|
96
97
|
echo "The last automatic restart was $INTERVAL seconds ago."
|
97
98
|
echo "Since this is greater than $<%= "#{auto_restart_count_clear_interval}" %> the restart count is being reset."
|
98
99
|
rm -f restart_count
|
@@ -112,7 +113,7 @@ echo $RESTART_COUNT > restart_count
|
|
112
113
|
# Check that we have not exceeded the maximum number of automatic restarts
|
113
114
|
if test $RESTART_COUNT -gt $<%= "#{max_auto_restart_count}" %>
|
114
115
|
then
|
115
|
-
echo "WARNING: <%= "User: #{
|
116
|
+
echo "WARNING: <%= "User: #{fetch(:user)} Application: #{fetch(:application)} Service: #{fetch(:tmp_delayed_job_runit_service_name)}" %>"
|
116
117
|
echo "Reached the limit of $<%= "#{max_auto_restart_count}" %> automatic restarts."
|
117
118
|
echo "The last automatic restart was within $<%= "#{auto_restart_count_clear_interval}" %> seconds."
|
118
119
|
echo "Manual intervention required. No further automatic restarts will be attempted."
|
@@ -125,7 +126,7 @@ then
|
|
125
126
|
SLEEP_TIME=$(expr $<%= "#{min_auto_restart_interval}" %> - $INTERVAL)
|
126
127
|
if test $SLEEP_TIME -gt 0
|
127
128
|
then
|
128
|
-
echo "NOTICE: Restart attempt $RESTART_COUNT for <%= "User: #{
|
129
|
+
echo "NOTICE: Restart attempt $RESTART_COUNT for <%= "User: #{fetch(:user)} Application: #{fetch(:application)} Service: #{fetch(:tmp_delayed_job_runit_service_name)}" %>"
|
129
130
|
echo "$INTERVAL seconds have elapsed since the last automatic restart."
|
130
131
|
echo "Sleeping for $SLEEP_TIME seconds before the next automatic restart ..."
|
131
132
|
sleep $SLEEP_TIME
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/bin/sh -e
|
2
|
+
# Log output for delayed_job worker <%= fetch(:tmp_worker_number) %> running on <%= fetch(:application) %> running as <%= fetch(:user) %>
|
3
|
+
# make sure the log directory exists
|
4
|
+
mkdir -p "<%= fetch(:tmp_delayed_job_log_path) %>"
|
5
|
+
# change path to the log directory
|
6
|
+
cd "<%= fetch(:tmp_delayed_job_log_path) %>"
|
7
|
+
# start logging
|
8
|
+
# exec chpst -u syslog svlogd -tt "<%= fetch(:tmp_delayed_job_log_path) %>"
|
9
|
+
exec svlogd -tt "<%= fetch(:tmp_delayed_job_log_path) %>"
|
data/templates/runit/run.erb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
#!/bin/bash --login
|
2
2
|
# Start delayed job using rake
|
3
|
-
|
3
|
+
# Delayed_Job worker <%= fetch(:tmp_worker_number) %> running on <%= fetch(:application) %> running as <%= fetch(:user) %>
|
4
|
+
|
4
5
|
# Redirect stderr so everything ends up in the log file
|
5
6
|
exec 2>&1
|
6
7
|
|
7
8
|
# Announce start
|
8
|
-
echo "<%= "User: #{
|
9
|
+
echo "<%= "User: #{fetch(:user)} Application: #{fetch(:application)} Service: #{fetch(:tmp_delayed_job_runit_service_name)}" %> starting..."
|
9
10
|
|
10
11
|
# Change path to current path
|
11
|
-
cd '<%=
|
12
|
+
cd '<%= current_path %>'
|
12
13
|
|
13
14
|
# Start delayed job
|
14
|
-
RAILS_ENV=<%=
|
15
|
+
RAILS_ENV=<%= environment %> exec <%= fetch(:delayed_job_bin) %>
|
metadata
CHANGED
@@ -1,80 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-delayed_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 3.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Leif Ringstad
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: capistrano
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: '3.4'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: '3.4'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: activesupport
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
33
|
+
version: '3.0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: capistrano-monit_runit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.1
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: bundler
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- -
|
59
|
+
- - "~>"
|
52
60
|
- !ruby/object:Gem::Version
|
53
|
-
version: 1.
|
61
|
+
version: '1.7'
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
65
|
requirements:
|
59
|
-
- -
|
66
|
+
- - "~>"
|
60
67
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
68
|
+
version: '1.7'
|
62
69
|
- !ruby/object:Gem::Dependency
|
63
70
|
name: jeweler
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
72
|
requirements:
|
67
|
-
- - ~>
|
73
|
+
- - "~>"
|
68
74
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
75
|
+
version: '2.0'
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
78
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
79
|
requirements:
|
75
|
-
- - ~>
|
80
|
+
- - "~>"
|
76
81
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
82
|
+
version: '2.0'
|
78
83
|
description: Capistrano recipes for Delayed Job using runit and monit.
|
79
84
|
email: leifcr@gmail.com
|
80
85
|
executables: []
|
@@ -91,39 +96,38 @@ files:
|
|
91
96
|
- VERSION
|
92
97
|
- capistrano-delayed_job.gemspec
|
93
98
|
- lib/capistrano/delayed_job.rb
|
94
|
-
- lib/capistrano/delayed_job/
|
95
|
-
- lib/capistrano/delayed_job/
|
96
|
-
- lib/capistrano/delayed_job/
|
99
|
+
- lib/capistrano/helpers/delayed_job/monit.rb
|
100
|
+
- lib/capistrano/helpers/delayed_job/runit.rb
|
101
|
+
- lib/capistrano/helpers/delayed_job/template_paths.rb
|
102
|
+
- lib/capistrano/tasks/config.rake
|
103
|
+
- lib/capistrano/tasks/monit.rake
|
104
|
+
- lib/capistrano/tasks/runit.rake
|
97
105
|
- templates/monit/delayed_job.conf.erb
|
98
106
|
- templates/runit/finish.erb
|
99
|
-
- templates/runit/log
|
107
|
+
- templates/runit/log/run.erb
|
100
108
|
- templates/runit/run.erb
|
101
109
|
homepage: https://github.com/leifcr/capistrano-delayed_job
|
102
110
|
licenses:
|
103
111
|
- MIT
|
112
|
+
metadata: {}
|
104
113
|
post_install_message:
|
105
114
|
rdoc_options: []
|
106
115
|
require_paths:
|
107
116
|
- lib
|
108
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
118
|
requirements:
|
111
|
-
- -
|
119
|
+
- - ">="
|
112
120
|
- !ruby/object:Gem::Version
|
113
121
|
version: '0'
|
114
|
-
segments:
|
115
|
-
- 0
|
116
|
-
hash: -2659159965666790878
|
117
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
-
none: false
|
119
123
|
requirements:
|
120
|
-
- -
|
124
|
+
- - ">="
|
121
125
|
- !ruby/object:Gem::Version
|
122
126
|
version: '0'
|
123
127
|
requirements: []
|
124
128
|
rubyforge_project:
|
125
|
-
rubygems_version:
|
129
|
+
rubygems_version: 2.4.6
|
126
130
|
signing_key:
|
127
|
-
specification_version:
|
131
|
+
specification_version: 4
|
128
132
|
summary: Capistrano recipes for Delayed Job using runit and monit
|
129
133
|
test_files: []
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'capistrano/base_helper/base_helper'
|
2
|
-
Capistrano::Configuration.instance(true).load do
|
3
|
-
_cset :delayed_job_runit_service_name, "delayed_job"
|
4
|
-
_cset :delayed_job_workers, 1 # More than 1 is not implemented yet.
|
5
|
-
|
6
|
-
_cset :delayed_job_bin, 'bundle exec rake jobs:work'
|
7
|
-
|
8
|
-
_cset :delayed_job_pid_file, defer {Capistrano::RunitBase::service_pid(fetch(:delayed_job_runit_service_name))}
|
9
|
-
|
10
|
-
# Logging to path
|
11
|
-
_cset :delayed_job_log_path, defer {"/var/log/service/#{fetch(:user)}/#{fetch(:application)}_#{Capistrano::BaseHelper.environment}/delayed_job"}
|
12
|
-
|
13
|
-
# runit defaults
|
14
|
-
_cset :delayed_job_restart_interval, defer {fetch(:runit_restart_interval)}
|
15
|
-
_cset :delayed_job_restart_count, defer {fetch(:runit_restart_count)}
|
16
|
-
_cset :delayed_job_autorestart_clear_interval, defer {fetch(:runit_autorestart_clear_interval)}
|
17
|
-
|
18
|
-
# runit paths
|
19
|
-
_cset :delayed_job_runit_local_run, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "runit", )), "run.erb")
|
20
|
-
_cset :delayed_job_runit_local_finish, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "runit", )), "finish.erb")
|
21
|
-
_cset :delayed_job_runit_control_q, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "runit")), "control-q.erb")
|
22
|
-
_cset :delayed_job_runit_local_log_run, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "runit")), "log-run.erb")
|
23
|
-
|
24
|
-
# monit configuration
|
25
|
-
_cset :delayed_job_monit_service_name, defer { "#{fetch(:user)}_#{fetch(:application)}_#{Capistrano::BaseHelper.environment}_delayed_job" }
|
26
|
-
_cset :delayed_job_monit_start_command, defer {"/bin/bash -c '[ ! -h #{Capistrano::RunitBase.service_path(fetch(:delayed_job_runit_service_name))}/run ] || /usr/bin/sv start #{Capistrano::RunitBase.service_path(fetch(:delayed_job_runit_service_name))}'"}
|
27
|
-
_cset :delayed_job_monit_stop_command, defer {"/usr/bin/sv -w 12 force-stop #{Capistrano::RunitBase.service_path(fetch(:delayed_job_runit_service_name))}"}
|
28
|
-
_cset :delayed_job_monit_memory_alert_threshold, "100.0 MB for 2 cycles" # Each worker would be likely to use at least 60-70mb ram for an app with many gems
|
29
|
-
_cset :delayed_job_monit_memory_restart_threshold, "150.0 MB for 3 cycles" # Give the delayed_job_workers some headroom
|
30
|
-
_cset :delayed_job_monit_cpu_alert_threshold, "90% for 2 cycles"
|
31
|
-
_cset :delayed_job_monit_cpu_restart_threshold, "95% for 5 cycles"
|
32
|
-
|
33
|
-
_cset :delayed_job_local_monit_config, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "monit")), "delayed_job.conf.erb")
|
34
|
-
|
35
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# Delayed Job - Monit
|
2
|
-
# Setup and management of Monit for Delayed Job
|
3
|
-
#
|
4
|
-
|
5
|
-
require 'capistrano/delayed_job/config'
|
6
|
-
require 'capistrano/base_helper/monit_base'
|
7
|
-
|
8
|
-
Capistrano::Configuration.instance(true).load do
|
9
|
-
after "monit:setup", "delayed_job:monit:setup"
|
10
|
-
after "delayed_job:monit:setup", "delayed_job:monit:enable"
|
11
|
-
after "delayed_job:monit:enable", "monit:reload"
|
12
|
-
|
13
|
-
before "delayed_job:monit.disable", "delayed_job:monit:unmonitor"
|
14
|
-
after "delayed_job:monit:disable", "monit:reload"
|
15
|
-
|
16
|
-
# start service after update in case it has not been stopped
|
17
|
-
# after "deploy:update", "delayed_job:monit:start"
|
18
|
-
# Not needed?
|
19
|
-
|
20
|
-
namespace :delayed_job do
|
21
|
-
namespace :monit do
|
22
|
-
desc "Setup Delayed Job monit-service"
|
23
|
-
task :setup, :roles => [:app, :web, :db] do
|
24
|
-
# Upload configuration
|
25
|
-
Capistrano::BaseHelper::generate_and_upload_config(delayed_job_local_monit_config, File.join(fetch(:monit_available_path), "#{fetch(:delayed_job_runit_service_name)}.conf"))
|
26
|
-
# Enable monitor
|
27
|
-
end
|
28
|
-
|
29
|
-
desc "Enable monit services for Delayed Job"
|
30
|
-
task :enable, :roles => [:app, :web, :db] do
|
31
|
-
Capistrano::MonitBase::Service.enable("#{fetch(:delayed_job_runit_service_name)}.conf")
|
32
|
-
end
|
33
|
-
|
34
|
-
desc "Disable and stop monit services for Delayed Job"
|
35
|
-
task :disable, :roles => [:app, :web, :db] do
|
36
|
-
Capistrano::MonitBase::Service.disable("#{fetch(:delayed_job_runit_service_name)}.conf")
|
37
|
-
end
|
38
|
-
|
39
|
-
desc "Start monit services for Delayed Job (will also try to start the service)"
|
40
|
-
task :start, :roles => [:app, :web, :db] do
|
41
|
-
Capistrano::MonitBase::Service.command_monit("start", fetch(:delayed_job_monit_service_name))
|
42
|
-
end
|
43
|
-
|
44
|
-
desc "Stop monit services for Delayed Job (will also stop the service)"
|
45
|
-
task :stop, :roles => [:app, :web, :db] do
|
46
|
-
Capistrano::MonitBase::Service.command_monit("stop", fetch(:delayed_job_monit_service_name))
|
47
|
-
end
|
48
|
-
|
49
|
-
desc "Restart monit services for Delayed Job"
|
50
|
-
task :restart, :roles => [:app, :web, :db] do
|
51
|
-
Capistrano::MonitBase::Service.command_monit("restart", fetch(:delayed_job_monit_service_name))
|
52
|
-
end
|
53
|
-
|
54
|
-
desc "Monitor Delayed Job"
|
55
|
-
task :monitor, :roles => [:app, :web, :db] do
|
56
|
-
Capistrano::MonitBase::Service.command_monit("monitor", fetch(:delayed_job_monit_service_name))
|
57
|
-
end
|
58
|
-
|
59
|
-
desc "Unmonitor Delayed Job"
|
60
|
-
task :unmonitor, :roles => [:app, :web, :db] do
|
61
|
-
Capistrano::MonitBase::Service.command_monit("unmonitor", fetch(:delayed_job_monit_service_name))
|
62
|
-
end
|
63
|
-
|
64
|
-
desc "Purge Delayed Job monit configuration"
|
65
|
-
task :unmonitor, :roles => [:app, :web, :db], :on_error => :continue do
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# Delayed Job - Runit
|
2
|
-
|
3
|
-
require 'capistrano/delayed_job/config'
|
4
|
-
require 'capistrano/base_helper/runit_base'
|
5
|
-
|
6
|
-
Capistrano::Configuration.instance(true).load do
|
7
|
-
after "deploy:setup", "delayed_job:runit:setup"
|
8
|
-
|
9
|
-
# enable service after update in case it has not been setup or is disabled
|
10
|
-
# Service should probably be started as well?
|
11
|
-
after "deploy:update", "delayed_job:runit:enable"
|
12
|
-
before "delayed_job:runit:quit", "delayed_job:runit:stop"
|
13
|
-
|
14
|
-
namespace :delayed_job do
|
15
|
-
namespace :runit do
|
16
|
-
desc "Setup Delayed Job runit-service"
|
17
|
-
task :setup, :roles => :app do
|
18
|
-
# Create runit config
|
19
|
-
Capistrano::RunitBase.create_service_dir(delayed_job_runit_service_name)
|
20
|
-
Capistrano::BaseHelper::generate_and_upload_config(delayed_job_runit_local_run, Capistrano::RunitBase.remote_run_config_path(delayed_job_runit_service_name))
|
21
|
-
Capistrano::BaseHelper::generate_and_upload_config(delayed_job_runit_local_finish, Capistrano::RunitBase.remote_finish_config_path(delayed_job_runit_service_name))
|
22
|
-
|
23
|
-
# Log run script
|
24
|
-
Capistrano::BaseHelper::generate_and_upload_config(delayed_job_runit_local_log_run, Capistrano::RunitBase.remote_service_log_run_path(delayed_job_runit_service_name))
|
25
|
-
|
26
|
-
# Make scripts executable
|
27
|
-
Capistrano::RunitBase.make_service_scripts_executeable(delayed_job_runit_service_name)
|
28
|
-
|
29
|
-
# Set correct permissions/owner on log path
|
30
|
-
Capistrano::RunitBase.create_and_permissions_on_path(fetch(:delayed_job_log_path))
|
31
|
-
end
|
32
|
-
|
33
|
-
desc "Enable Delayed Job runit-service"
|
34
|
-
task :enable, :roles => :app do
|
35
|
-
Capistrano::RunitBase.enable_service(delayed_job_runit_service_name)
|
36
|
-
end
|
37
|
-
|
38
|
-
desc "Disable Delayed Job runit-service"
|
39
|
-
task :disable, :roles => :app do
|
40
|
-
Capistrano::RunitBase.disable_service(delayed_job_runit_service_name)
|
41
|
-
end
|
42
|
-
|
43
|
-
desc "Start Delayed Job runit-service"
|
44
|
-
task :start, :roles => :app do
|
45
|
-
Capistrano::RunitBase.start_service(delayed_job_runit_service_name)
|
46
|
-
end
|
47
|
-
|
48
|
-
desc "Start Delayed Job runit-service only ONCE (no supervision...)"
|
49
|
-
task :once, :roles => :app do
|
50
|
-
Capistrano::RunitBase.start_service_once(delayed_job_runit_service_name)
|
51
|
-
end
|
52
|
-
|
53
|
-
desc "Stop Delayed Job runit-service"
|
54
|
-
task :stop, :roles => :app, :on_error => :continue do
|
55
|
-
# have to use force-stop on failed stop, since delayed_job might not terminate properly
|
56
|
-
# will wait 25 seconds for delayed_job to shut down, to allow it to serve any on-going requests
|
57
|
-
Capistrano::RunitBase.control_service(delayed_job_runit_service_name, "force-stop", false, "-w 25")
|
58
|
-
end
|
59
|
-
|
60
|
-
desc "Quit the Delayed Job runit-service"
|
61
|
-
task :quit, :roles => :app, :on_error => :continue do
|
62
|
-
Capistrano::RunitBase.control_service(delayed_job_runit_service_name, "quit")
|
63
|
-
end
|
64
|
-
|
65
|
-
desc "Restart Delayed Job runit-service"
|
66
|
-
task :restart, :roles => :app do
|
67
|
-
Capistrano::RunitBase.control_service(delayed_job_runit_service_name, "restart")
|
68
|
-
end
|
69
|
-
|
70
|
-
desc "Purge Delayed Job runit configuration"
|
71
|
-
task :purge, :roles => :app, :on_error => :continue do
|
72
|
-
Capistrano::RunitBase.force_control_service(delayed_job_runit_service_name, "force-stop", true)
|
73
|
-
Capistrano::RunitBase.purge_service(delayed_job_runit_service_name)
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/templates/runit/log-run.erb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/bin/sh -e
|
2
|
-
<% c = Capistrano::BaseHelper::get_capistrano_instance %>
|
3
|
-
# Log output for delayed_job running on <%= c.fetch(:application) %> running as <%= c.fetch(:user) %>
|
4
|
-
# make sure the log directory exists
|
5
|
-
mkdir -p "<%= c.fetch(:delayed_job_log_path) %>"
|
6
|
-
# change path to the log directory
|
7
|
-
cd "<%= c.fetch(:delayed_job_log_path) %>"
|
8
|
-
# start logging
|
9
|
-
# exec chpst -u syslog svlogd -tt "<%= c.fetch(:delayed_job_log_path) %>"
|
10
|
-
exec svlogd -tt "<%= c.fetch(:delayed_job_log_path) %>"
|