red_unicorn 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +6 -1
- data/bin/red_unicorn +4 -0
- data/lib/red_unicorn/unicorn.rb +41 -24
- data/lib/red_unicorn/version.rb +1 -1
- metadata +30 -51
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -16,6 +16,7 @@ provide zero downtime restarts.
|
|
16
16
|
-t, --timeout 30 Specify timeout for running actions
|
17
17
|
-g, --restart-grace 8 Specify grace time to start replacement children (default: 8 seconds)
|
18
18
|
-e, --env production Specify environment (default: production)
|
19
|
+
-k, --kind (unicorn|gunicorn) Specify kind of unicorn in use (default: unicorn)
|
19
20
|
Commands:
|
20
21
|
prolicide: Kill single worker process
|
21
22
|
status: Returns current unicorn status
|
@@ -33,6 +34,10 @@ unicorn the restart signal, it will wait until the new unicorn process has forke
|
|
33
34
|
out workers before killing the original unicorn process. If no worker processes
|
34
35
|
are started, the old unicorn process will be left running.
|
35
36
|
|
37
|
+
=== Unicorn agnostic
|
38
|
+
|
39
|
+
RedUnicorn is compatible with unicorn and gunicorn.
|
40
|
+
|
36
41
|
== Bugs and Feature requests
|
37
42
|
|
38
43
|
* Fork, make updates and send pull request
|
@@ -40,5 +45,5 @@ are started, the old unicorn process will be left running.
|
|
40
45
|
|
41
46
|
== License
|
42
47
|
|
43
|
-
Copyright (c)
|
48
|
+
Copyright (c) 2012 Chris Roberts <chrisroberts.code@gmail.com>
|
44
49
|
Licensed under the MIT license (see LICENSE)
|
data/bin/red_unicorn
CHANGED
@@ -7,6 +7,7 @@ require 'red_unicorn'
|
|
7
7
|
require 'red_unicorn/unicorn'
|
8
8
|
|
9
9
|
opts = GetoptLong.new(
|
10
|
+
['--kind', '-k', GetoptLong::REQUIRED_ARGUMENT],
|
10
11
|
['--pid-file', '-p', GetoptLong::REQUIRED_ARGUMENT],
|
11
12
|
['--unicorn-exec', '-x', GetoptLong::REQUIRED_ARGUMENT],
|
12
13
|
['--unicorn-config', '-c', GetoptLong::REQUIRED_ARGUMENT],
|
@@ -53,6 +54,7 @@ def print_help
|
|
53
54
|
puts ' -t, --timeout 30 Specify timeout for running actions'
|
54
55
|
puts ' -g, --restart-grace 8 Specify grace time to start replacement children (default: 8 seconds)'
|
55
56
|
puts ' -e, --env production Specify environment (default: production)'
|
57
|
+
puts ' -k, --kind (unicorn|gunicorn) Specify kind of unicorn in use (default: unicorn)'
|
56
58
|
puts 'Commands:'
|
57
59
|
max_width = ALLOWED_ACTIONS.keys.map(&:to_s).map(&:length).max + 8
|
58
60
|
ALLOWED_ACTIONS.each_pair do |action, message|
|
@@ -75,6 +77,8 @@ opts.each do |opt,arg|
|
|
75
77
|
unicorn_hash[:pid] = arg.to_s
|
76
78
|
when '--env'
|
77
79
|
unicorn_hash[:env] = arg.to_s
|
80
|
+
when '--kind'
|
81
|
+
unicorn_hash[:kind] = arg.to_s
|
78
82
|
when '--help'
|
79
83
|
print_help
|
80
84
|
exit RETURN_CODES[:success]
|
data/lib/red_unicorn/unicorn.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
#TODO: Add method of checking for rouge unicorn process and killing them
|
2
1
|
module RedUnicorn
|
3
2
|
|
4
3
|
# Descriptive error classes
|
@@ -25,7 +24,8 @@ module RedUnicorn
|
|
25
24
|
:config_path => '/etc/unicorn/app.rb',
|
26
25
|
:action_timeout => 30,
|
27
26
|
:restart_grace => 8,
|
28
|
-
:env => 'production'
|
27
|
+
:env => 'production',
|
28
|
+
:kind => 'unicorn'
|
29
29
|
}.merge(opts)
|
30
30
|
check_exec_path
|
31
31
|
end
|
@@ -33,7 +33,7 @@ module RedUnicorn
|
|
33
33
|
# Start a new unicorn process
|
34
34
|
def start
|
35
35
|
process_is :stopped do
|
36
|
-
%x{#{@opts[:exec_path]}
|
36
|
+
%x{#{@opts[:exec_path]} #{format_options}}
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -53,28 +53,33 @@ module RedUnicorn
|
|
53
53
|
|
54
54
|
# Graceful restart
|
55
55
|
def restart
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
56
|
+
begin
|
57
|
+
process_is :running do
|
58
|
+
original_pid = pid
|
59
|
+
Process.kill('USR2', pid)
|
60
|
+
sleep(@opts[:restart_grace]) # give unicorn some breathing room
|
61
|
+
waited = 0
|
62
|
+
until((File.exists?(@opts[:pid]) && is_running? && !child_pids(pid).empty?) || waited > @opts[:action_timeout])
|
63
|
+
sleep_start = Time.now.to_f
|
64
|
+
sleep(0.2)
|
65
|
+
waited += Time.now.to_f - sleep_start
|
66
|
+
end
|
67
|
+
if(pid == original_pid || waited > @opts[:action_timeout])
|
68
|
+
raise UnicornError.new 'Failed to start new process'
|
69
|
+
end
|
70
|
+
Process.kill('QUIT', original_pid)
|
71
|
+
while(is_running?(original_pid) && waited < @opts[:action_timeout])
|
72
|
+
sleep_start = Time.now.to_f
|
73
|
+
sleep(0.2)
|
74
|
+
waited += Time.now.to_f - sleep_start
|
75
|
+
end
|
76
|
+
raise IsRunning.new 'Failed to stop original unicorn process' if is_running?(original_pid)
|
77
|
+
raise NotRunning.new 'Failed to start new unicorn process' unless is_running?
|
78
|
+
reopen_logs
|
74
79
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
80
|
+
rescue NotRunning
|
81
|
+
puts "WARN: #{@opts[:kind]} not currently running. Starting."
|
82
|
+
start
|
78
83
|
end
|
79
84
|
end
|
80
85
|
|
@@ -178,6 +183,18 @@ module RedUnicorn
|
|
178
183
|
end
|
179
184
|
end
|
180
185
|
end
|
186
|
+
|
187
|
+
# Formats options based on kind of unicorn
|
188
|
+
def format_options
|
189
|
+
case @opts[:kind].to_sym
|
190
|
+
when :unicorn
|
191
|
+
"--daemonize --env #{@opts[:env]} --config-file #{@opts[:config_path]} --pid-file #{@opts[:pid]}"
|
192
|
+
when :gunicorn
|
193
|
+
"--daemon --config #{@opts[:config_path]} --pid #{@opts[:pid]}"
|
194
|
+
else
|
195
|
+
raise UnicornError.new("Unknown unicorn type provided (#{kind}). Supported: unicorn, gunicorn")
|
196
|
+
end
|
197
|
+
end
|
181
198
|
end
|
182
199
|
end
|
183
200
|
|
data/lib/red_unicorn/version.rb
CHANGED
metadata
CHANGED
@@ -1,86 +1,65 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: red_unicorn
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.6
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
- 5
|
10
|
-
version: 1.1.5
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Chris Roberts
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-04-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: unicorn
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &18527620 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *18527620
|
35
25
|
description: Unicorn Process Handler
|
36
26
|
email: chrisroberts.code@gmail.com
|
37
|
-
executables:
|
27
|
+
executables:
|
38
28
|
- red_unicorn
|
39
29
|
extensions: []
|
40
|
-
|
41
|
-
extra_rdoc_files:
|
30
|
+
extra_rdoc_files:
|
42
31
|
- README.rdoc
|
43
32
|
- CHANGELOG.rdoc
|
44
|
-
files:
|
33
|
+
files:
|
45
34
|
- README.rdoc
|
46
35
|
- CHANGELOG.rdoc
|
47
36
|
- bin/red_unicorn
|
48
37
|
- lib/red_unicorn.rb
|
49
38
|
- lib/red_unicorn/unicorn.rb
|
50
39
|
- lib/red_unicorn/version.rb
|
51
|
-
has_rdoc: true
|
52
40
|
homepage: http://github.com/chrisroberts/red_unicorn
|
53
41
|
licenses: []
|
54
|
-
|
55
42
|
post_install_message:
|
56
43
|
rdoc_options: []
|
57
|
-
|
58
|
-
require_paths:
|
44
|
+
require_paths:
|
59
45
|
- lib
|
60
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
47
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
-
|
67
|
-
- 0
|
68
|
-
version: "0"
|
69
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
53
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
version: "0"
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
78
58
|
requirements: []
|
79
|
-
|
80
59
|
rubyforge_project:
|
81
|
-
rubygems_version: 1.
|
60
|
+
rubygems_version: 1.8.17
|
82
61
|
signing_key:
|
83
62
|
specification_version: 3
|
84
63
|
summary: Unicorn Process Handler
|
85
64
|
test_files: []
|
86
|
-
|
65
|
+
has_rdoc:
|