rbg 0.9.4 → 1.0.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.
- data/bin/rbg +7 -3
- data/lib/rbg.rb +18 -7
- data/lib/rbg/config.rb +19 -23
- metadata +5 -4
data/bin/rbg
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
require 'rbg'
|
3
3
|
|
4
4
|
def die
|
5
|
-
|
6
|
-
|
5
|
+
puts "Usage: rbg run|start|stop|reload [-c config_file] [-E environment]"
|
6
|
+
Process.exit(1)
|
7
7
|
end
|
8
8
|
|
9
9
|
begin
|
@@ -19,6 +19,10 @@ begin
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
if config_file.nil?
|
23
|
+
config_file = "ProcessFile"
|
24
|
+
end
|
25
|
+
|
22
26
|
die unless config_file
|
23
27
|
|
24
28
|
case command
|
@@ -28,7 +32,7 @@ begin
|
|
28
32
|
Rbg.start(config_file, {:background => true, :environment => environment})
|
29
33
|
when 'stop'
|
30
34
|
Rbg.stop(config_file, {:environment => environment})
|
31
|
-
when 'reload'
|
35
|
+
when 'reload', 'restart'
|
32
36
|
Rbg.reload(config_file, {:environment => environment})
|
33
37
|
else
|
34
38
|
die
|
data/lib/rbg.rb
CHANGED
@@ -98,8 +98,11 @@ module Rbg
|
|
98
98
|
# Execure before_fork code
|
99
99
|
self.config.after_fork.call
|
100
100
|
|
101
|
-
|
102
|
-
|
101
|
+
if self.config.script.is_a?(String)
|
102
|
+
require self.config.script
|
103
|
+
elsif self.config.script.is_a?(Proc)
|
104
|
+
self.config.script.call
|
105
|
+
end
|
103
106
|
end
|
104
107
|
|
105
108
|
# Print some debug info and save the pid
|
@@ -143,13 +146,13 @@ module Rbg
|
|
143
146
|
# This will load the before_fork in a clean process then fork the script as required
|
144
147
|
self.start_parent
|
145
148
|
|
146
|
-
#
|
149
|
+
# A restart is not required yet...
|
150
|
+
restart_needed = false
|
151
|
+
|
152
|
+
# If we get a USR1, set this process as waiting for a restart
|
147
153
|
Signal.trap("USR1", proc {
|
148
154
|
puts "Master got a USR1."
|
149
|
-
|
150
|
-
self.kill_child_processes
|
151
|
-
load_config
|
152
|
-
self.start_parent
|
155
|
+
restart_needed = true
|
153
156
|
})
|
154
157
|
|
155
158
|
# If we get a TERM, send the existing workers a TERM before bowing out
|
@@ -171,6 +174,14 @@ module Rbg
|
|
171
174
|
# Main loop, we mostly idle, but check if the parent we created has died and exit
|
172
175
|
loop do
|
173
176
|
sleep 2
|
177
|
+
if restart_needed
|
178
|
+
STDOUT.flush
|
179
|
+
self.kill_child_processes
|
180
|
+
load_config
|
181
|
+
self.start_parent
|
182
|
+
restart_needed = false
|
183
|
+
end
|
184
|
+
|
174
185
|
self.child_processes.each do |p|
|
175
186
|
begin
|
176
187
|
Process.getpgid( p )
|
data/lib/rbg/config.rb
CHANGED
@@ -1,39 +1,35 @@
|
|
1
1
|
module Rbg
|
2
2
|
class Config
|
3
3
|
|
4
|
-
## The name of the application as used in the proclist
|
5
4
|
attr_accessor :name
|
6
|
-
|
7
|
-
## The ruby script which should be backgrounded
|
5
|
+
attr_accessor :root
|
8
6
|
attr_accessor :script
|
9
|
-
|
10
|
-
## Path to the log file for the master process
|
11
7
|
attr_accessor :log_path
|
12
|
-
|
13
|
-
## Path to the PID file for the master process
|
14
8
|
attr_accessor :pid_path
|
15
|
-
|
16
|
-
## Number of workers to start
|
17
9
|
attr_accessor :workers
|
18
10
|
|
19
|
-
|
20
|
-
|
11
|
+
def root
|
12
|
+
@root || File.expand_path('./')
|
13
|
+
end
|
14
|
+
|
15
|
+
def log_path
|
16
|
+
@log_path || File.join(root, 'log', "#{name}.log")
|
17
|
+
end
|
18
|
+
|
19
|
+
def pid_path
|
20
|
+
@pid_path || File.join(root, 'log', "#{name}.pid")
|
21
|
+
end
|
22
|
+
|
23
|
+
def script(&block)
|
24
|
+
block_given? ? @script = block : @script
|
25
|
+
end
|
26
|
+
|
21
27
|
def before_fork(&block)
|
22
|
-
|
23
|
-
@before_fork = block
|
24
|
-
else
|
25
|
-
@before_fork
|
26
|
-
end
|
28
|
+
block_given? ? @before_fork = block : @before_fork
|
27
29
|
end
|
28
30
|
|
29
|
-
## Block of code to be executed in the child process after forking has
|
30
|
-
## taken place.
|
31
31
|
def after_fork(&block)
|
32
|
-
|
33
|
-
@after_fork = block
|
34
|
-
else
|
35
|
-
@after_fork
|
36
|
-
end
|
32
|
+
block_given? ? @after_fork = block : @after_fork
|
37
33
|
end
|
38
34
|
|
39
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
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:
|
12
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: charlie@atechmedia.com
|
@@ -19,8 +19,8 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- bin/rbg
|
22
|
-
- lib/rbg.rb
|
23
22
|
- lib/rbg/config.rb
|
23
|
+
- lib/rbg.rb
|
24
24
|
homepage: http://www.atechmedia.com
|
25
25
|
licenses: []
|
26
26
|
post_install_message:
|
@@ -41,9 +41,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
43
|
rubyforge_project:
|
44
|
-
rubygems_version: 1.8.
|
44
|
+
rubygems_version: 1.8.23
|
45
45
|
signing_key:
|
46
46
|
specification_version: 3
|
47
47
|
summary: Ruby Backgrounder allows multiple copies of ruby scripts to be run in the
|
48
48
|
background and restarted
|
49
49
|
test_files: []
|
50
|
+
has_rdoc: false
|