ringleader 1.0.0 → 1.0.1

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/CHANGES.md ADDED
@@ -0,0 +1,9 @@
1
+ 1.0.1
2
+ ---
3
+ * Warn but proxy anyway to processes running outside ringleader's control
4
+ * Add support for environment variable overrides in app config file
5
+ * Support `rbenv` key in config for rbenv-managed projects
6
+
7
+ 1.0.0
8
+ ---
9
+ * Initial release
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
  ```
@@ -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
 
@@ -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
@@ -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 %Q(bash -c "#{config.command}"),
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.
@@ -1,3 +1,3 @@
1
1
  module Ringleader
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -11,6 +11,8 @@ admin:
11
11
  command: "bundle exec foreman start"
12
12
  server_port: 3001
13
13
  app_port: 4001
14
+ env:
15
+ OVERRIDE: true
14
16
  authentication:
15
17
  dir: "~/apps/auth"
16
18
  command: "bundle exec foreman start"
@@ -0,0 +1,7 @@
1
+ ---
2
+ rbenv_app:
3
+ dir: "~/apps/main"
4
+ rbenv: "bundle exec foreman start"
5
+ server_port: 3000
6
+ app_port: 4000
7
+
@@ -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.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-06 00:00:00.000000000 Z
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