Created
June 15, 2011 05:45
-
-
Save avdi/1026546 to your computer and use it in GitHub Desktop.
A Guardfile for starting Redis
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
module ::Guard | |
class Redis < Guard | |
def start | |
puts "Starting Redis on port #{port}" | |
IO.popen("#{executable} -", 'w+') do |server| | |
server.write(config) | |
server.close_write | |
end | |
puts "Redis is running with PID #{pid}" | |
$?.success? | |
end | |
def stop | |
if pid | |
puts "Sending TERM signal to Redis (#{pid})" | |
Process.kill("TERM", pid) | |
true | |
end | |
end | |
def reload | |
stop | |
start | |
end | |
def run_all | |
true | |
end | |
def run_on_change(paths) | |
true | |
end | |
private | |
def pidfile_path | |
options.fetch(:pidfile) { | |
File.expand_path('tmp/redis.pid', File.dirname(__FILE__)) | |
} | |
end | |
def config | |
<<"END" | |
daemonize yes | |
pidfile #{pidfile_path} | |
port #{port} | |
END | |
end | |
def pid | |
File.exist?(pidfile_path) && File.read(pidfile_path).to_i | |
end | |
def executable | |
options.fetch(:executable){'redis-server'} | |
end | |
def port | |
options.fetch(:port){6379} | |
end | |
end | |
end | |
# Available options: :pidfile, :port, :executable | |
guard 'redis' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment