Skip to content

Instantly share code, notes, and snippets.

@jonathanpenn
Created February 17, 2009 06:58
Show Gist options
  • Save jonathanpenn/65615 to your computer and use it in GitHub Desktop.
Save jonathanpenn/65615 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# SERVER_COMMAND = 'spin'
SERVER_COMMAND = 'script/server'
POLL_TIME = 1.1 # In Seconds
@states = {}
def check_for_changes
changes = []
Dir.glob("./**/*").reject do |file|
file =~ %r{^\./(log|public|doc)}
end.each do |file|
unless File.symlink?(file)
new_time = File.stat(file).mtime
if @states[file] != new_time
@states[file] = new_time
changes << file
end
end
end
changes
end
p1 = fork { exec SERVER_COMMAND }
Signal.trap(0) do
Process.kill("KILL", p1)
end
check_for_changes
loop do
sleep POLL_TIME
changes = check_for_changes
unless changes.empty?
print "\n\n\nChanges found..."
p changes
puts "\n\n"
Process.kill("KILL", p1)
p1 = fork { exec SERVER_COMMAND }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment