ringleader 0.0.1 → 0.0.2
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/README.md +4 -2
- data/lib/ringleader/app.rb +13 -13
- data/lib/ringleader/app_proxy.rb +1 -1
- data/lib/ringleader/cli.rb +5 -2
- data/lib/ringleader/config.rb +4 -2
- data/lib/ringleader/version.rb +1 -1
- data/spec/fixtures/config.yml +3 -3
- data/spec/fixtures/invalid.yml +1 -1
- data/spec/ringleader/config_spec.rb +5 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -61,9 +61,11 @@ main_app:
|
|
61
61
|
# the port ringleader listens on
|
62
62
|
server_port: 3000
|
63
63
|
# the port the application listens on
|
64
|
-
|
65
|
-
# idle timeout in seconds
|
64
|
+
app_port: 4000
|
65
|
+
# idle timeout in seconds
|
66
66
|
idle_timeout: 6000
|
67
|
+
# application startup timeout
|
68
|
+
startup_timeout: 180
|
67
69
|
other_app:
|
68
70
|
[...]
|
69
71
|
```
|
data/lib/ringleader/app.rb
CHANGED
@@ -54,6 +54,7 @@ module Ringleader
|
|
54
54
|
return unless @pid
|
55
55
|
|
56
56
|
info "stopping `#{config.command}`"
|
57
|
+
@master.close unless @master.closed?
|
57
58
|
Process.kill "SIGHUP", -@pid
|
58
59
|
|
59
60
|
timer = after 30 do
|
@@ -71,7 +72,7 @@ module Ringleader
|
|
71
72
|
|
72
73
|
# Internal: callback for when the application port has opened
|
73
74
|
def port_opened
|
74
|
-
info "listening on #{config.hostname}:#{config.
|
75
|
+
info "listening on #{config.hostname}:#{config.app_port}"
|
75
76
|
signal :running, true
|
76
77
|
end
|
77
78
|
|
@@ -96,26 +97,25 @@ module Ringleader
|
|
96
97
|
@starting = true
|
97
98
|
info "starting process `#{config.command}`"
|
98
99
|
|
99
|
-
#
|
100
|
-
|
101
|
-
# give the child process a terminal
|
102
|
-
master, slave = PTY.open
|
100
|
+
# give the child process a terminal so output isn't buffered
|
101
|
+
@master, slave = PTY.open
|
103
102
|
@pid = Process.spawn %Q(bash -c "#{config.command}"),
|
104
|
-
:in =>
|
103
|
+
:in => slave,
|
105
104
|
:out => slave,
|
106
105
|
:err => slave,
|
107
|
-
:
|
108
|
-
:
|
109
|
-
stdin.close
|
110
|
-
stdout.close
|
106
|
+
:chdir => config.dir,
|
107
|
+
:pgroup => true
|
111
108
|
slave.close
|
112
|
-
proxy_output master
|
109
|
+
proxy_output @master
|
113
110
|
debug "started with pid #{@pid}"
|
114
111
|
|
115
112
|
@wait_for_exit = WaitForExit.new @pid, Actor.current
|
116
|
-
@wait_for_port = WaitForPort.new config.hostname, config.
|
113
|
+
@wait_for_port = WaitForPort.new config.hostname, config.app_port, Actor.current
|
117
114
|
|
118
|
-
timer = after
|
115
|
+
timer = after config.startup_timeout do
|
116
|
+
warn "application startup took more than #{config.startup_timeout}"
|
117
|
+
stop!
|
118
|
+
end
|
119
119
|
|
120
120
|
@running = wait :running
|
121
121
|
@starting = false
|
data/lib/ringleader/app_proxy.rb
CHANGED
data/lib/ringleader/cli.rb
CHANGED
@@ -54,6 +54,7 @@ module Ringleader
|
|
54
54
|
app
|
55
55
|
end
|
56
56
|
|
57
|
+
# gracefully die instead of showing an interrupted sleep below
|
57
58
|
trap("INT") do
|
58
59
|
info "shutting down..."
|
59
60
|
apps.each { |app| app.stop! }
|
@@ -118,9 +119,11 @@ something like this:
|
|
118
119
|
# the port ringleader listens on
|
119
120
|
server_port: 3000
|
120
121
|
# the port the application listens on
|
121
|
-
|
122
|
-
# idle timeout in seconds, defaults to
|
122
|
+
app_port: 4000
|
123
|
+
# idle timeout in seconds, defaults to #{Config::DEFAULT_IDLE_TIMEOUT}. 0 means "never".
|
123
124
|
idle_timeout: 6000
|
125
|
+
# application startup timeout, defaults to #{Config::DEFAULT_STARTUP_TIMEOUT}.
|
126
|
+
startup_timeout: 180
|
124
127
|
other_app:
|
125
128
|
[...]
|
126
129
|
|
data/lib/ringleader/config.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module Ringleader
|
2
2
|
class Config
|
3
3
|
|
4
|
-
DEFAULT_IDLE_TIMEOUT =
|
4
|
+
DEFAULT_IDLE_TIMEOUT = 1800
|
5
|
+
DEFAULT_STARTUP_TIMEOUT = 30
|
5
6
|
DEFAULT_HOSTNAME = "127.0.0.1"
|
6
|
-
REQUIRED_KEYS = %w(dir command server_port
|
7
|
+
REQUIRED_KEYS = %w(dir command server_port app_port idle_timeout)
|
7
8
|
|
8
9
|
def initialize(file)
|
9
10
|
@config = YAML.load(File.read(file))
|
@@ -15,6 +16,7 @@ module Ringleader
|
|
15
16
|
options["name"] = name
|
16
17
|
options["hostname"] ||= DEFAULT_HOSTNAME
|
17
18
|
options["idle_timeout"] ||= DEFAULT_IDLE_TIMEOUT
|
19
|
+
options["startup_timeout"] ||= DEFAULT_STARTUP_TIMEOUT
|
18
20
|
validate name, options
|
19
21
|
[name, OpenStruct.new(options)]
|
20
22
|
end
|
data/lib/ringleader/version.rb
CHANGED
data/spec/fixtures/config.yml
CHANGED
@@ -4,15 +4,15 @@ main_site:
|
|
4
4
|
command: "bundle exec foreman start"
|
5
5
|
hostname: "0.0.0.0"
|
6
6
|
server_port: 3000
|
7
|
-
|
7
|
+
app_port: 4000
|
8
8
|
idle_timeout: 1800
|
9
9
|
admin:
|
10
10
|
dir: "~/apps/admin"
|
11
11
|
command: "bundle exec foreman start"
|
12
12
|
server_port: 3001
|
13
|
-
|
13
|
+
app_port: 4001
|
14
14
|
authentication:
|
15
15
|
dir: "~/apps/auth"
|
16
16
|
command: "bundle exec foreman start"
|
17
17
|
server_port: 3002
|
18
|
-
|
18
|
+
app_port: 4002
|
data/spec/fixtures/invalid.yml
CHANGED
@@ -20,7 +20,11 @@ describe Ringleader::Config do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "includes a default idle timeout" do
|
23
|
-
expect(subject.apps["admin"].idle_timeout).to eq(
|
23
|
+
expect(subject.apps["admin"].idle_timeout).to eq(Ringleader::Config::DEFAULT_IDLE_TIMEOUT)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets a default start timeout" do
|
27
|
+
expect(subject.apps["admin"].startup_timeout).to eq(Ringleader::Config::DEFAULT_STARTUP_TIMEOUT)
|
24
28
|
end
|
25
29
|
|
26
30
|
it "sets the config name to match the key in the config file" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ringleader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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: 2012-07-
|
12
|
+
date: 2012-07-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: celluloid
|