public
Created

A Guardfile for starting Redis

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
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'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.