Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for configuring einhorn via environment variables

Closes: #4
  • Loading branch information...
commit ef4bcd597d665985977893926299603ccda957be 1 parent 0acfae8
@gdb gdb authored
Showing with 17 additions and 0 deletions.
  1. +13 −0 lib/einhorn.rb
  2. +4 −0 lib/einhorn/command.rb
View
13 lib/einhorn.rb
@@ -38,6 +38,8 @@ def self.default_state
:version => 0,
:sockets => {},
:orig_cmd => nil,
+ :bind => [],
+ :bind_fds => [],
:cmd => nil,
:script_name => nil,
:respawn => true,
@@ -218,9 +220,19 @@ def self.worker_ps_name
Einhorn::State.cmd_name ? "ruby #{Einhorn::State.cmd_name}" : Einhorn::State.orig_cmd.join(' ')
end
+ def self.socketify_env!
+ Einhorn::State.bind.each do |host, port, flags|
+ fd = bind(host, port, flags)
+ Einhorn::State.bind_fds << fd
+ end
+ end
+
+ # This duplicates some code from the environment path, but is
+ # deprecated so that's ok.
def self.socketify!(cmd)
cmd.map! do |arg|
if arg =~ /^(.*=|)srv:([^:]+):(\d+)((?:,\w+)*)$/
+ log_error("Using deprecated command-line configuration for Einhorn; should upgrade to the environment variable interface.")
opt = $1
host = $2
port = $3
@@ -248,6 +260,7 @@ def self.run
Einhorn::State.cmd = ARGV.dup
# TODO: don't actually alter ARGV[0]?
Einhorn::State.cmd[0] = which(Einhorn::State.cmd[0])
+ socketify_env!
socketify!(Einhorn::State.cmd)
end
View
4 lib/einhorn/command.rb
@@ -237,6 +237,10 @@ def self.prepare_child_environment
Einhorn::TransientState.socket_handles << socket
ENV['EINHORN_SOCK_FD'] = socket.fileno.to_s
end
+ # Try to match Upstart's internal support for space-separated FD
+ # lists. (I don't think anyone actually uses that functionality,
+ # but seems reasonable enough.)
+ ENV['EINHORN_FDS'] = Einhorn::State.bind_fds.map(&:to_s).join(' ')
end
def self.full_upgrade
Please sign in to comment.
Something went wrong with that request. Please try again.