Skip to content

Commit

Permalink
Wait for server running, Chrome auto-refresh
Browse files Browse the repository at this point in the history
Using process spawn rather than fork to enable waiting for “Server
running” rather than sleep 5 (more reliable). Probably should have some
process recovery in case this never happens. Also added an osascript to
automatically refresh current tab in Chrome so changes will be
automatically seen.
  • Loading branch information
dport9696 committed Feb 6, 2017
1 parent 287c4e2 commit ee6ecbe
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions morea-watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@
end

def fork_MOREA()
pid = fork do
exec "./morea-run-local.sh"
end
# stdout, stderr pipes
rout, wout = IO.pipe
rerr, werr = IO.pipe

pid = Process.spawn("./morea-run-local.sh", :out => wout, :err => werr)
Process.detach(pid)
sleep 5

# Wait until we see the MOREA server is running
until (line=rout.gets) =~ /Server running/
puts(line)
end
wout.close
werr.close

return pid
end

Expand Down Expand Up @@ -80,6 +89,8 @@ def fork_MOREA()
puts "goodby pid #{morea_pid}, restarting MOREA"
end
morea_pid = fork_MOREA
# If using Chrome, tell it to reload the page so changes can be seen
`osascript -e 'tell application "Google Chrome" to tell the active tab of its first window to reload'`
end
sleep 1
end
end

0 comments on commit ee6ecbe

Please sign in to comment.