Skip to content

Instantly share code, notes, and snippets.

@avdi
Created June 15, 2011 05:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save avdi/1026546 to your computer and use it in GitHub Desktop.
Save avdi/1026546 to your computer and use it in GitHub Desktop.
A Guardfile for starting Redis
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