2016-02-06 22:28:02 -08:00
|
|
|
require 'puma/plugin'
|
|
|
|
|
|
|
|
Puma::Plugin.create do
|
|
|
|
def start(launcher)
|
|
|
|
path = File.join("tmp", "restart.txt")
|
|
|
|
|
2016-02-26 10:11:59 -08:00
|
|
|
orig = nil
|
2016-02-06 22:28:02 -08:00
|
|
|
|
2016-02-26 10:11:59 -08:00
|
|
|
# If we can't write to the path, then just don't bother with this plugin
|
|
|
|
begin
|
|
|
|
File.write path, ""
|
|
|
|
orig = File.stat(path).mtime
|
|
|
|
rescue SystemCallError
|
|
|
|
return
|
|
|
|
end
|
2016-02-06 22:28:02 -08:00
|
|
|
|
|
|
|
in_background do
|
|
|
|
while true
|
|
|
|
sleep 2
|
|
|
|
|
2016-02-26 10:11:59 -08: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-06 22:28:02 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|