Created
February 17, 2009 06:58
-
-
Save jonathanpenn/65615 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
POLL_DIRECTORIES = %w(app config db lib) | |
POLL_TIME = 0.9 # In Seconds | |
SERVER_COMMAND = "script/server" | |
Dir.chdir(File.dirname(__FILE__)+"/..") | |
@states = {} | |
def check_for_changes | |
changes = [] | |
Dir[*POLL_DIRECTORIES.map{|i|i+"/**/*"}].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 | |
def emphasized(m) | |
"\e[1;1m\e[41m \e[0m \e[1;1m\e[5m #{m} \e[0m" | |
end | |
p1 = fork { exec SERVER_COMMAND } | |
Signal.trap(0) do | |
Process.kill("KILL", p1) | |
end | |
check_for_changes | |
$stderr.puts "server_restarter running...watching #{@states.length} files every #{POLL_TIME} seconds." | |
loop do | |
sleep POLL_TIME | |
changes = check_for_changes | |
unless changes.empty? | |
$stderr.puts emphasized("Changes found...#{changes.inspect}") | |
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