2013-02-25 10:42:20 -06:00
|
|
|
# this is a trivial graceful restart on touch of tmp/restart.
|
2013-02-15 20:54:23 -06:00
|
|
|
#
|
|
|
|
# It simply drains all the requests (waits up to 4 seconds) and issues a HUP
|
|
|
|
# if you need a more sophisticated cycling restart for multiple thins it will need to be written
|
|
|
|
#
|
|
|
|
# This works fine for Discourse.org cause we host our app accross multiple machines, if you hosting
|
|
|
|
# on a single machine you have a trickier problem at hand as you need to cycle the processes in order
|
|
|
|
|
2013-02-25 10:42:20 -06:00
|
|
|
Thread.new do
|
2013-02-05 13:16:51 -06:00
|
|
|
file = "#{Rails.root}/tmp/restart"
|
2013-02-15 20:54:23 -06:00
|
|
|
old_time = File.ctime(file).to_i if File.exists? file
|
|
|
|
wait_seconds = 4
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2013-10-09 21:33:52 -05:00
|
|
|
if $PROGRAM_NAME =~ /thin/
|
|
|
|
while true
|
|
|
|
time = File.ctime(file).to_i if File.exists? file
|
2013-02-25 10:42:20 -06:00
|
|
|
|
2013-10-09 21:33:52 -05:00
|
|
|
if old_time != time
|
|
|
|
Rails.logger.info "attempting to reload #{$$} #{$PROGRAM_NAME} in #{wait_seconds} seconds"
|
|
|
|
$shutdown = true
|
|
|
|
sleep wait_seconds
|
|
|
|
Rails.logger.info "restarting #{$$}"
|
|
|
|
Process.kill("HUP", $$)
|
|
|
|
break
|
|
|
|
end
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2013-10-09 21:33:52 -05:00
|
|
|
sleep 1
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|