add a launchctl script for redis-server

Signed-off-by: Adam Vandenberg <flangy@gmail.com>
This commit is contained in:
Corey Donohoe 2010-05-29 13:57:40 -07:00 committed by Adam Vandenberg
parent 9423dba851
commit 8fe3bb0ef7

View file

@ -15,26 +15,54 @@ class Redis <Formula
bin.install p rescue nil bin.install p rescue nil
} }
%w( run db/redis log ).each do |path| %w( run db/redis log ).each { |p| (var+p).mkpath }
(var+path).mkpath
end
# Fix up default conf file to match our paths # Fix up default conf file to match our paths
inreplace "redis.conf" do |s| inreplace "redis.conf" do |s|
s.gsub! "/var/run/redis.pid", "#{var}/run/redis.pid" s.gsub! "/var/run/redis.pid", "#{var}/run/redis.pid"
s.gsub! "dir ./", "dir #{var}/db/redis/" s.gsub! "dir ./", "dir #{var}/db/redis/"
end end
etc.install "redis.conf" etc.install "redis.conf"
(prefix+'io.redis.redis-server.plist').write startup_plist
end end
def caveats def caveats
<<-EOS.undent <<-EOS.undent
To start redis: Automatically load on login with:
launchctl load -w #{prefix}/io.redis.redis-server.plist
To start redis manually:
redis-server #{etc}/redis.conf redis-server #{etc}/redis.conf
To access the server: To access the server:
redis-cli redis-cli
EOS EOS
end end
def startup_plist
return <<-EOPLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>io.redis.redis-server</string>
<key>ProgramArguments</key>
<array>
<string>#{bin}/redis-server</string>
<string>#{etc}/redis.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>#{`whoami`.chomp}</string>
<key>WorkingDirectory</key>
<string>#{var}</string>
</dict>
</plist>
EOPLIST
end
end end