ringleader 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +9 -0
- data/README.md +6 -0
- data/lib/ringleader/cli.rb +6 -0
- data/lib/ringleader/config.rb +4 -0
- data/lib/ringleader/process.rb +18 -1
- data/lib/ringleader/version.rb +1 -1
- data/spec/fixtures/config.yml +2 -0
- data/spec/fixtures/rbenv.yml +7 -0
- data/spec/ringleader/config_spec.rb +15 -1
- metadata +5 -2
data/CHANGES.md
ADDED
data/README.md
CHANGED
@@ -92,12 +92,18 @@ main_app:
|
|
92
92
|
idle_timeout: 6000 # Idle timeout in seconds
|
93
93
|
startup_timeout: 180 # Application startup timeout
|
94
94
|
disabled: true # Set the app to be disabled when ringleader starts
|
95
|
+
env: # Override or set environment variables inherited
|
96
|
+
FOO: hello # from the current environment. Use nil to unset a
|
97
|
+
BAR: nil # var.
|
95
98
|
|
96
99
|
# If you have an application managed by rvm, this setting automatically adds
|
97
100
|
# the rvm-specific shell setup before executing the given command. This
|
98
101
|
# supersedes the `command` setting.
|
99
102
|
rvm: "foreman start"
|
100
103
|
|
104
|
+
# Likewise for rbenv:
|
105
|
+
rbenv: "foreman start"
|
106
|
+
|
101
107
|
other_app:
|
102
108
|
[...]
|
103
109
|
```
|
data/lib/ringleader/cli.rb
CHANGED
@@ -98,12 +98,18 @@ something like this:
|
|
98
98
|
idle_timeout: 6000 # Idle timeout in seconds
|
99
99
|
startup_timeout: 180 # Application startup timeout
|
100
100
|
disabled: true # Set the app to be disabled when ringleader starts
|
101
|
+
env: # Override or set environment variables inherited
|
102
|
+
FOO: hello # from the current environment. Use nil to unset a
|
103
|
+
BAR: nil # var.
|
101
104
|
|
102
105
|
# If you have an application managed by rvm, this setting automatically
|
103
106
|
# adds the rvm-specific shell setup before executing the given command.
|
104
107
|
# This supersedes the `command` setting.
|
105
108
|
rvm: "foreman start"
|
106
109
|
|
110
|
+
# Likewise for rbenv:
|
111
|
+
rbenv: "foreman start"
|
112
|
+
|
107
113
|
OPTIONS
|
108
114
|
banner
|
109
115
|
|
data/lib/ringleader/config.rb
CHANGED
@@ -37,9 +37,13 @@ module Ringleader
|
|
37
37
|
options["host"] ||= DEFAULT_HOST
|
38
38
|
options["idle_timeout"] ||= DEFAULT_IDLE_TIMEOUT
|
39
39
|
options["startup_timeout"] ||= DEFAULT_STARTUP_TIMEOUT
|
40
|
+
options["env"] ||= {}
|
40
41
|
|
41
42
|
if command = options.delete("rvm")
|
42
43
|
options["command"] = "source ~/.rvm/scripts/rvm && rvm --with-rubies rvmrc exec -- #{command}"
|
44
|
+
elsif command = options.delete("rbenv")
|
45
|
+
options["command"] = "rbenv exec #{command}"
|
46
|
+
options["env"]["RBENV_VERSION"] = nil
|
43
47
|
end
|
44
48
|
|
45
49
|
validate name, options
|
data/lib/ringleader/process.rb
CHANGED
@@ -90,17 +90,25 @@ module Ringleader
|
|
90
90
|
#
|
91
91
|
# Returns true if the app started, false if not.
|
92
92
|
def start_app
|
93
|
+
if already_running?
|
94
|
+
warn "#{config.name} already running on port #{config.app_port}"
|
95
|
+
return true
|
96
|
+
end
|
97
|
+
|
93
98
|
@starting = true
|
94
99
|
info "starting process `#{config.command}`"
|
95
100
|
|
96
101
|
# give the child process a terminal so output isn't buffered
|
97
102
|
@master, slave = PTY.open
|
98
|
-
@pid = ::Process.spawn
|
103
|
+
@pid = ::Process.spawn(
|
104
|
+
config.env,
|
105
|
+
%Q(bash -c "#{config.command}"),
|
99
106
|
:in => slave,
|
100
107
|
:out => slave,
|
101
108
|
:err => slave,
|
102
109
|
:chdir => config.dir,
|
103
110
|
:pgroup => true
|
111
|
+
)
|
104
112
|
slave.close
|
105
113
|
proxy_output @master
|
106
114
|
debug "started with pid #{@pid}"
|
@@ -129,6 +137,15 @@ module Ringleader
|
|
129
137
|
end
|
130
138
|
end
|
131
139
|
|
140
|
+
# Private: check if the app is already running outside ringleader
|
141
|
+
def already_running?
|
142
|
+
socket = TCPSocket.new config.host, config.app_port
|
143
|
+
socket.close
|
144
|
+
true
|
145
|
+
rescue Errno::ECONNREFUSED
|
146
|
+
false
|
147
|
+
end
|
148
|
+
|
132
149
|
# Private: proxy output streams to the logger.
|
133
150
|
#
|
134
151
|
# Fire and forget, runs in its own thread.
|
data/lib/ringleader/version.rb
CHANGED
data/spec/fixtures/config.yml
CHANGED
@@ -12,7 +12,7 @@ describe Ringleader::Config do
|
|
12
12
|
|
13
13
|
it "returns a hash of configurations" do
|
14
14
|
config = subject.apps["main_site"]
|
15
|
-
expect(config.dir).to eq("~/apps/main")
|
15
|
+
expect(config.dir).to eq(File.expand_path("~/apps/main"))
|
16
16
|
end
|
17
17
|
|
18
18
|
it "includes a default host" do
|
@@ -30,6 +30,11 @@ describe Ringleader::Config do
|
|
30
30
|
it "sets the config name to match the key in the config file" do
|
31
31
|
expect(subject.apps["admin"].name).to eq("admin")
|
32
32
|
end
|
33
|
+
|
34
|
+
it "sets the env hash to an empty hash if not specified" do
|
35
|
+
expect(subject.apps["main_site"].env).to eq({})
|
36
|
+
expect(subject.apps["admin"].env).to have_key("OVERRIDE")
|
37
|
+
end
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
@@ -64,4 +69,13 @@ describe Ringleader::Config do
|
|
64
69
|
end
|
65
70
|
end
|
66
71
|
|
72
|
+
context "with a config with a 'rbenv' key instead of 'command'" do
|
73
|
+
it "replaces the 'rbenv' command with an rbenv command and environment" do
|
74
|
+
config = Ringleader::Config.new "spec/fixtures/rbenv.yml"
|
75
|
+
expect(config.apps["rbenv_app"].command).to eq("rbenv exec bundle exec foreman start")
|
76
|
+
expect(config.apps["rbenv_app"].env).to have_key("RBENV_VERSION")
|
77
|
+
expect(config.apps["rbenv_app"].env["RBENV_VERSION"]).to eq(nil)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
67
81
|
end
|
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: 1.0.
|
4
|
+
version: 1.0.1
|
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-08-
|
12
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: celluloid
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- .gitignore
|
151
151
|
- .rspec
|
152
152
|
- .rvmrc
|
153
|
+
- CHANGES.md
|
153
154
|
- Gemfile
|
154
155
|
- Guardfile
|
155
156
|
- LICENSE
|
@@ -201,6 +202,7 @@ files:
|
|
201
202
|
- spec/fixtures/invalid.yml
|
202
203
|
- spec/fixtures/no_app_port.yml
|
203
204
|
- spec/fixtures/no_server_port.yml
|
205
|
+
- spec/fixtures/rbenv.yml
|
204
206
|
- spec/fixtures/rvm.yml
|
205
207
|
- spec/ringleader/config_spec.rb
|
206
208
|
- spec/spec_helper.rb
|
@@ -233,6 +235,7 @@ test_files:
|
|
233
235
|
- spec/fixtures/invalid.yml
|
234
236
|
- spec/fixtures/no_app_port.yml
|
235
237
|
- spec/fixtures/no_server_port.yml
|
238
|
+
- spec/fixtures/rbenv.yml
|
236
239
|
- spec/fixtures/rvm.yml
|
237
240
|
- spec/ringleader/config_spec.rb
|
238
241
|
- spec/spec_helper.rb
|