ringleader 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
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
- port: 4000
65
- # idle timeout in seconds, defaults to 0. 0 means "never".
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
  ```
@@ -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.port}"
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
- # need a pipe for input, even if we don't use it
100
- stdin, stdout = ::IO.pipe
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 => stdin,
103
+ :in => slave,
105
104
  :out => slave,
106
105
  :err => slave,
107
- :pgroup => true,
108
- :chdir => config.dir
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.port, Actor.current
113
+ @wait_for_port = WaitForPort.new config.hostname, config.app_port, Actor.current
117
114
 
118
- timer = after(30) { warn "application startup took too long"; stop! }
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
@@ -45,7 +45,7 @@ module Ringleader
45
45
  end
46
46
 
47
47
  def proxy_to_app(socket)
48
- SocketProxy.new socket, config.hostname, config.port
48
+ SocketProxy.new socket, config.hostname, config.app_port
49
49
  end
50
50
 
51
51
  def start_activity_timer
@@ -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
- port: 4000
122
- # idle timeout in seconds, defaults to 0. 0 means "never".
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
 
@@ -1,9 +1,10 @@
1
1
  module Ringleader
2
2
  class Config
3
3
 
4
- DEFAULT_IDLE_TIMEOUT = 0
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 port idle_timeout)
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
@@ -1,3 +1,3 @@
1
1
  module Ringleader
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
- port: 4000
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
- port: 4001
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
- port: 4002
18
+ app_port: 4002
@@ -2,4 +2,4 @@
2
2
  main_site:
3
3
  dir: "~/apps/main"
4
4
  server_port: 3000
5
- port: 4000
5
+ app_port: 4000
@@ -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(0)
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.1
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-17 00:00:00.000000000 Z
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid