Permalink
Browse files

Merge pull request #9 from ebroder/restore-env

Store the environment at startup and restore it before reexecing
  • Loading branch information...
gdb committed Aug 25, 2012
2 parents 7df866c + 9e09420 commit e9496c006b2945904ece61013da0c98a617a4816
Showing with 6 additions and 0 deletions.
  1. +1 −0 bin/einhorn
  2. +1 −0 lib/einhorn.rb
  3. +4 −0 lib/einhorn/command.rb
View
@@ -167,6 +167,7 @@ end
if true # $0 == __FILE__
Einhorn::TransientState.script_name = $0
Einhorn::TransientState.argv = ARGV.dup
+ Einhorn::TransientState.environ = ENV.to_hash
optparse = OptionParser.new do |opts|
opts.on('-b', '--command-socket-as-fd', 'Leave the command socket open as a file descriptor, passed in the EINHORN_FD environment variable. This allows your worker processes to ACK without needing to know where on the filesystem the command socket lives.') do
View
@@ -68,6 +68,7 @@ def self.default_state
:preloaded => false,
:script_name => nil,
:argv => [],
+ :environ => {},
:has_outstanding_spinup_timer => false,
:stateful => nil,
# Holds references so that the GC doesn't go and close your sockets.
View
@@ -172,6 +172,10 @@ def self.reload
Einhorn::Event.uninit
+ # Reload the original environment
+ ENV.clear
+ ENV.update(Einhorn::TransientState.environ)
+
exec [Einhorn::TransientState.script_name, Einhorn::TransientState.script_name], *(['--with-state-fd', read.fileno.to_s, '--'] + Einhorn::State.cmd)
end

0 comments on commit e9496c0

Please sign in to comment.