Created
April 1, 2010 13:13
-
-
Save floere/351776 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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