2016-02-07 01:28:02 -05:00
|
|
|
require 'puma/plugin'
|
|
|
|
|
|
|
|
Puma::Plugin.create do
|
|
|
|
def start(launcher)
|
|
|
|
path = File.join("tmp", "restart.txt")
|
|
|
|
|
2016-02-26 13:11:59 -05:00
|
|
|
orig = nil
|
2016-02-07 01:28:02 -05:00
|
|
|
|
2016-02-26 13:11:59 -05:00
|
|
|
# If we can't write to the path, then just don't bother with this plugin
|
|
|
|
begin
|
2017-02-23 12:26:47 -05:00
|
|
|
File.write(path, "") unless File.exist?(path)
|
2016-02-26 13:11:59 -05:00
|
|
|
orig = File.stat(path).mtime
|
|
|
|
rescue SystemCallError
|
|
|
|
return
|
|
|
|
end
|
2016-02-07 01:28:02 -05:00
|
|
|
|
|
|
|
in_background do
|
|
|
|
while true
|
|
|
|
sleep 2
|
|
|
|
|
2016-02-26 13:11:59 -05:00
|
|
|
begin
|
|
|
|
mtime = File.stat(path).mtime
|
|
|
|
rescue SystemCallError
|
|
|
|
# If the file has disappeared, assume that means don't restart
|
|
|
|
else
|
|
|
|
if mtime > orig
|
|
|
|
launcher.restart
|
|
|
|
break
|
|
|
|
end
|
2016-02-07 01:28:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|