capistrano-delayed_job 0.0.3 → 0.0.4
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.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/VERSION +1 -1
- data/capistrano-delayed_job.gemspec +6 -5
- data/lib/capistrano/delayed_job/config.rb +8 -2
- data/lib/capistrano/delayed_job/runit.rb +2 -4
- data/templates/runit/finish.erb +135 -0
- data/templates/runit/run.erb +9 -1
- metadata +6 -5
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -9,7 +9,7 @@ GEM
|
|
9
9
|
net-sftp (>= 2.0.0)
|
10
10
|
net-ssh (>= 2.0.14)
|
11
11
|
net-ssh-gateway (>= 1.1.0)
|
12
|
-
capistrano-base_helper (0.0.
|
12
|
+
capistrano-base_helper (0.0.6)
|
13
13
|
capistrano (>= 2.15.5)
|
14
14
|
faraday (0.8.7)
|
15
15
|
multipart-post (~> 1.1)
|
@@ -65,5 +65,5 @@ PLATFORMS
|
|
65
65
|
DEPENDENCIES
|
66
66
|
bundler (>= 1.3.0)
|
67
67
|
capistrano (>= 2.15.5)
|
68
|
-
capistrano-base_helper (>= 0.0.
|
68
|
+
capistrano-base_helper (>= 0.0.6)
|
69
69
|
jeweler (~> 1.8.6)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "capistrano-delayed_job"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Leif Ringstad"]
|
12
|
-
s.date = "2013-07-
|
12
|
+
s.date = "2013-07-08"
|
13
13
|
s.description = "Capistrano recipes for Delayed Job using runit and monit."
|
14
14
|
s.email = "leifcr@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/capistrano/delayed_job/monit.rb",
|
30
30
|
"lib/capistrano/delayed_job/runit.rb",
|
31
31
|
"templates/monit/delayed_job.conf.erb",
|
32
|
+
"templates/runit/finish.erb",
|
32
33
|
"templates/runit/log-run.erb",
|
33
34
|
"templates/runit/run.erb"
|
34
35
|
]
|
@@ -43,18 +44,18 @@ Gem::Specification.new do |s|
|
|
43
44
|
|
44
45
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
46
|
s.add_runtime_dependency(%q<capistrano>, [">= 2.15.5"])
|
46
|
-
s.add_runtime_dependency(%q<capistrano-base_helper>, [">= 0.0.
|
47
|
+
s.add_runtime_dependency(%q<capistrano-base_helper>, [">= 0.0.6"])
|
47
48
|
s.add_development_dependency(%q<bundler>, [">= 1.3.0"])
|
48
49
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.6"])
|
49
50
|
else
|
50
51
|
s.add_dependency(%q<capistrano>, [">= 2.15.5"])
|
51
|
-
s.add_dependency(%q<capistrano-base_helper>, [">= 0.0.
|
52
|
+
s.add_dependency(%q<capistrano-base_helper>, [">= 0.0.6"])
|
52
53
|
s.add_dependency(%q<bundler>, [">= 1.3.0"])
|
53
54
|
s.add_dependency(%q<jeweler>, ["~> 1.8.6"])
|
54
55
|
end
|
55
56
|
else
|
56
57
|
s.add_dependency(%q<capistrano>, [">= 2.15.5"])
|
57
|
-
s.add_dependency(%q<capistrano-base_helper>, [">= 0.0.
|
58
|
+
s.add_dependency(%q<capistrano-base_helper>, [">= 0.0.6"])
|
58
59
|
s.add_dependency(%q<bundler>, [">= 1.3.0"])
|
59
60
|
s.add_dependency(%q<jeweler>, ["~> 1.8.6"])
|
60
61
|
end
|
@@ -10,8 +10,14 @@ Capistrano::Configuration.instance(true).load do
|
|
10
10
|
# Logging to path
|
11
11
|
_cset :delayed_job_log_path, defer {"/var/log/service/#{fetch(:user)}/#{fetch(:application)}_#{Capistrano::BaseHelper.environment}/delayed_job"}
|
12
12
|
|
13
|
-
# runit
|
14
|
-
_cset :
|
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")
|
15
21
|
_cset :delayed_job_runit_control_q, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "runit")), "control-q.erb")
|
16
22
|
_cset :delayed_job_runit_local_log_run, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "runit")), "log-run.erb")
|
17
23
|
|
@@ -17,10 +17,8 @@ Capistrano::Configuration.instance(true).load do
|
|
17
17
|
task :setup, :roles => :app do
|
18
18
|
# Create runit config
|
19
19
|
Capistrano::RunitBase.create_service_dir(delayed_job_runit_service_name)
|
20
|
-
Capistrano::BaseHelper::generate_and_upload_config(
|
21
|
-
|
22
|
-
# Capistrano::BaseHelper::generate_and_upload_config(delayed_job_runit_control_q, Capistrano::RunitBase.remote_control_path(delayed_job_runit_service_name, "q"))
|
23
|
-
# Capistrano::BaseHelper::generate_and_upload_config(delayed_job_runit_control_q, Capistrano::RunitBase.remote_control_path(delayed_job_runit_service_name, "s"))
|
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))
|
24
22
|
|
25
23
|
# Log run script
|
26
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))
|
@@ -0,0 +1,135 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# This finish file is originally from:
|
4
|
+
# https://github.com/erwbgy/puppet-runit/blob/fde6006e6d400f0c99b6ff0b1b63094207dc8783/templates/service/finish.erb
|
5
|
+
# Thanks to erwbgy!
|
6
|
+
#
|
7
|
+
# <% c = Capistrano::BaseHelper::get_capistrano_instance %>
|
8
|
+
# Variable name setup
|
9
|
+
<%
|
10
|
+
exit_code = "EXIT_CODE_#{Capistrano::BaseHelper.user_app_env_underscore_short}_#{c.fetch(:delayed_job_runit_service_name)}".upcase
|
11
|
+
exit_status = "EXIT_STATUS_#{Capistrano::BaseHelper.user_app_env_underscore_short}_#{c.fetch(:delayed_job_runit_service_name)}".upcase
|
12
|
+
min_auto_restart_interval = "MIN_AUTO_RESTART_INTERVAL_#{Capistrano::BaseHelper.user_app_env_underscore_short}_#{c.fetch(:delayed_job_runit_service_name)}".upcase
|
13
|
+
max_auto_restart_count = "MAX_AUTO_RESTART_COUNT_#{Capistrano::BaseHelper.user_app_env_underscore_short}_#{c.fetch(:delayed_job_runit_service_name)}".upcase
|
14
|
+
auto_restart_count_clear_interval = "AUTO_RESTART_COUNT_CLEAR_INTERVAL_#{Capistrano::BaseHelper.user_app_env_underscore_short}_#{c.fetch(:delayed_job_runit_service_name)}".upcase
|
15
|
+
%>
|
16
|
+
#
|
17
|
+
# The following variables are set by Runit:
|
18
|
+
#
|
19
|
+
# <%= "#{exit_code}" %>: ./run's exit code
|
20
|
+
#
|
21
|
+
# <%= "#{exit_status}" %>: The least significant byte of the exit status as determined by
|
22
|
+
# waitpid(2); for instance it is 0 if ./run exited normally, and the signal
|
23
|
+
# number if ./run was terminated by a signal.
|
24
|
+
#
|
25
|
+
# The following configuration variables must be set:
|
26
|
+
#
|
27
|
+
# <%= "#{min_auto_restart_interval}" %>: The minimum delay (in seconds) between automatic restarts
|
28
|
+
#
|
29
|
+
# <%= "#{max_auto_restart_count}" %>: The maximum number of automatic restarts allowed
|
30
|
+
#
|
31
|
+
# <%= "#{auto_restart_count_clear_interval}" %>: Reset the restart count if
|
32
|
+
# <%= "#{auto_restart_count_clear_interval}" %> seconds have elapsed since the last
|
33
|
+
# automatic restart.
|
34
|
+
#
|
35
|
+
# Creates two new files in the service directory:
|
36
|
+
#
|
37
|
+
# last_finish - the Unix time (seconds since 1970) when the ./finish script
|
38
|
+
# last ran
|
39
|
+
#
|
40
|
+
# restart_count - the number of automatic restarts that have taken place
|
41
|
+
#
|
42
|
+
# These files must be removed BEFORE the service is cleanly shut down.
|
43
|
+
|
44
|
+
### Configuration
|
45
|
+
|
46
|
+
# ./run's exit code
|
47
|
+
<%= "#{exit_code}" %>=$1
|
48
|
+
|
49
|
+
# The least significant byte of the exit status as determined by waitpid(2);
|
50
|
+
# for instance it is 0 if ./run exited normally, and the signal number if
|
51
|
+
# ./run was terminated by a signal.
|
52
|
+
<%= "#{exit_status}" %>=$2
|
53
|
+
|
54
|
+
# The minimum delay (in seconds) between automatic restarts
|
55
|
+
<%= "#{min_auto_restart_interval}" %>=<%= c.fetch(:delayed_job_restart_interval) %>
|
56
|
+
|
57
|
+
# The maximum number of automatic restarts allowed
|
58
|
+
<%= "#{max_auto_restart_count}" %>=<%= c.fetch(:delayed_job_restart_count) %>
|
59
|
+
|
60
|
+
# Reset the restart count if <%= "#{auto_restart_count_clear_interval}" %> seconds
|
61
|
+
# have elapsed since the last automatic restart.
|
62
|
+
<%= "#{auto_restart_count_clear_interval}" %>=<%= c.fetch(:delayed_job_autorestart_clear_interval) %>
|
63
|
+
|
64
|
+
export <%= "#{exit_code}" %>
|
65
|
+
export <%= "#{exit_status}" %>
|
66
|
+
export <%= "#{min_auto_restart_interval}" %>
|
67
|
+
export <%= "#{max_auto_restart_count}" %>
|
68
|
+
export <%= "#{auto_restart_count_clear_interval }" %>
|
69
|
+
|
70
|
+
### Normally no changes should be made after this point
|
71
|
+
|
72
|
+
echo "<%= "User: #{c.fetch(:user)} Application: #{c.fetch(:application)} Service: #{c.fetch(:delayed_job_runit_service_name)}" %> finish; exit code: $<%= "#{exit_code}" %>; exit status: $<%= "#{exit_status}" %>"
|
73
|
+
|
74
|
+
if test $<%= "#{exit_code}" %> -eq 0 -a $<%= "#{exit_status}" %> -eq 0
|
75
|
+
then
|
76
|
+
echo "Clean shutdown."
|
77
|
+
sv down .
|
78
|
+
exit 0
|
79
|
+
fi
|
80
|
+
|
81
|
+
NOW=$(date +%s)
|
82
|
+
|
83
|
+
# Determine when the finish script last ran
|
84
|
+
if test -r last_finish
|
85
|
+
then
|
86
|
+
LAST_FINISH=$(head -1 last_finish)
|
87
|
+
INTERVAL=$(expr $NOW - $LAST_FINISH)
|
88
|
+
fi
|
89
|
+
echo $NOW > last_finish
|
90
|
+
|
91
|
+
# Remove the restart_count file if <%= "#{auto_restart_count_clear_interval}" %> seconds
|
92
|
+
# have elapsed since the last automatic restart.
|
93
|
+
if test $INTERVAL -gt $<%= "#{auto_restart_count_clear_interval}" %>
|
94
|
+
then
|
95
|
+
echo "NOTICE: <%= "User: #{c.fetch(:user)} Application: #{c.fetch(:application)} Service: #{c.fetch(:delayed_job_runit_service_name)}" %>"
|
96
|
+
echo "The last automatic restart was $INTERVAL seconds ago."
|
97
|
+
echo "Since this is greater than $<%= "#{auto_restart_count_clear_interval}" %> the restart count is being reset."
|
98
|
+
rm -f restart_count
|
99
|
+
fi
|
100
|
+
|
101
|
+
# Determine how many automatic restarts we have had
|
102
|
+
# and then increment this value by one
|
103
|
+
if test -r restart_count
|
104
|
+
then
|
105
|
+
RESTART_COUNT=$(head -1 restart_count)
|
106
|
+
RESTART_COUNT=$(expr $RESTART_COUNT + 1)
|
107
|
+
else
|
108
|
+
RESTART_COUNT=1
|
109
|
+
fi
|
110
|
+
echo $RESTART_COUNT > restart_count
|
111
|
+
|
112
|
+
# Check that we have not exceeded the maximum number of automatic restarts
|
113
|
+
if test $RESTART_COUNT -gt $<%= "#{max_auto_restart_count}" %>
|
114
|
+
then
|
115
|
+
echo "WARNING: <%= "User: #{c.fetch(:user)} Application: #{c.fetch(:application)} Service: #{c.fetch(:delayed_job_runit_service_name)}" %>"
|
116
|
+
echo "Reached the limit of $<%= "#{max_auto_restart_count}" %> automatic restarts."
|
117
|
+
echo "The last automatic restart was within $<%= "#{auto_restart_count_clear_interval}" %> seconds."
|
118
|
+
echo "Manual intervention required. No further automatic restarts will be attempted."
|
119
|
+
sv down .
|
120
|
+
exit 0
|
121
|
+
fi
|
122
|
+
|
123
|
+
if test -n "$INTERVAL"
|
124
|
+
then
|
125
|
+
SLEEP_TIME=$(expr $<%= "#{min_auto_restart_interval}" %> - $INTERVAL)
|
126
|
+
if test $SLEEP_TIME -gt 0
|
127
|
+
then
|
128
|
+
echo "NOTICE: Restart attempt $RESTART_COUNT for <%= "User: #{c.fetch(:user)} Application: #{c.fetch(:application)} Service: #{c.fetch(:delayed_job_runit_service_name)}" %>"
|
129
|
+
echo "$INTERVAL seconds have elapsed since the last automatic restart."
|
130
|
+
echo "Sleeping for $SLEEP_TIME seconds before the next automatic restart ..."
|
131
|
+
sleep $SLEEP_TIME
|
132
|
+
fi
|
133
|
+
fi
|
134
|
+
|
135
|
+
exit 0
|
data/templates/runit/run.erb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
#!/bin/bash --login
|
2
2
|
# Start delayed job using rake
|
3
3
|
<% c = Capistrano::BaseHelper::get_capistrano_instance %>
|
4
|
-
|
4
|
+
# Redirect stderr so everything ends up in the log file
|
5
5
|
exec 2>&1
|
6
|
+
|
7
|
+
# Announce start
|
8
|
+
echo "<%= "User: #{c.fetch(:user)} Application: #{c.fetch(:application)} Service: #{c.fetch(:delayed_job_runit_service_name)}" %> starting..."
|
9
|
+
|
10
|
+
# Change path to current path
|
11
|
+
cd '<%= c.current_path %>'
|
12
|
+
|
13
|
+
# Start delayed job
|
6
14
|
RAILS_ENV=<%= Capistrano::BaseHelper.environment %> exec <%= c.fetch(:delayed_job_bin) %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-delayed_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.0.
|
37
|
+
version: 0.0.6
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.0.
|
45
|
+
version: 0.0.6
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: bundler
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- lib/capistrano/delayed_job/monit.rb
|
96
96
|
- lib/capistrano/delayed_job/runit.rb
|
97
97
|
- templates/monit/delayed_job.conf.erb
|
98
|
+
- templates/runit/finish.erb
|
98
99
|
- templates/runit/log-run.erb
|
99
100
|
- templates/runit/run.erb
|
100
101
|
homepage: https://github.com/leifcr/capistrano-delayed_job
|
@@ -112,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
113
|
version: '0'
|
113
114
|
segments:
|
114
115
|
- 0
|
115
|
-
hash:
|
116
|
+
hash: -3670686879823204823
|
116
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
118
|
none: false
|
118
119
|
requirements:
|