Permalink
Browse files

Store the environment at startup and restore it before reexecing

This makes sure that pre-loaded code isn't able to change the
environment in ways that impact subsequent restarts of einhorn (for
instance by repointing bundler to look at a different Gemfile).

Fixes einhorn issue #7
  • Loading branch information...
1 parent 7df866c commit 9e0942086c8dc5f0a8f14f95df50cd517abde5ce @ebroder ebroder committed Aug 19, 2012
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
1 bin/einhorn
@@ -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
1 lib/einhorn.rb
@@ -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
4 lib/einhorn/command.rb
@@ -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 9e09420

Please sign in to comment.