Skip to content

Instantly share code, notes, and snippets.

@floere
Created April 1, 2010 13:13
Show Gist options
  • Save floere/351776 to your computer and use it in GitHub Desktop.
Save floere/351776 to your computer and use it in GitHub Desktop.
# The following code can be used to reload a
# running application with updated code, for example
# in a unicorn process.
#
# In e.g. a file loader.rb
#
module Loader
def self.selfload
@@selfload
end
def self.selfload= value
@@selfload = value
end
@@selfload = true
def self.selfload!
exclaim 'Loader loading itself.'
load __FILE__ # load self
Loader.selfload = false
load!
end
def self.load!
return selfload! if selfload
#
# Load your application here using load, not require.
#
end
end
# Somewhere else...
#
# Installing a signal that lets the user send the USR1
# signal to the application to reload it.
#
Signal.trap 'USR1' do
Loader.load!
end
# Then for example in the Terminal
#
kill -USR1 <pid>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment