class Ssdb < Formula homepage "http://ssdb.io/" url "https://github.com/ideawu/ssdb/archive/1.8.0.tar.gz" sha1 "88f4930ae6f3d0234c783546e1fb00638801c4e7" head "https://github.com/ideawu/ssdb.git" revision 1 bottle do sha1 "61b35f6fc12408e55863344feab5af1a8fbd3d88" => :yosemite sha1 "3e6a066798981b12d02885fa4ee3358bf3f251a2" => :mavericks sha1 "807e32ab2af2db9fbaa1a4104c1a5e065c3a9231" => :mountain_lion end def install inreplace "Makefile", "PREFIX=/usr/local/ssdb", "PREFIX=#{prefix}" system "make", "prefix=#{prefix} CC=#{ENV.cc} CXX=#{ENV.cxx}" system "make", "install" ["bench", "dump", "ins.sh", "repair", "server"].each do |suffix| bin.install "#{prefix}/ssdb-#{suffix}" end ["run", "db/ssdb", "log"].each do |dir| (var+dir).mkpath end inreplace "ssdb.conf" do |s| s.gsub! "work_dir = ./var", "work_dir = #{var}/db/ssdb/" s.gsub! "pidfile = ./var/ssdb.pid", "pidfile = #{var}/run/ssdb.pid" s.gsub! "\toutput: log.txt", "\toutput: #{var}/log/ssdb.log" end inreplace "ssdb_slave.conf" do |s| s.gsub! "work_dir = ./var_slave", "work_dir = #{var}/db/ssdb/" s.gsub! "pidfile = ./var_slave/ssdb.pid", "pidfile = #{var}/run/ssdb_slave.pid" s.gsub! "\toutput: log_slave.txt", "\toutput: #{var}/log/ssdb_slave.log" end etc.install "ssdb.conf" etc.install "ssdb_slave.conf" end plist_options :manual => "ssdb-server #{HOMEBREW_PREFIX}/etc/ssdb.conf" def plist; <<-EOS.undent KeepAlive SuccessfulExit Label #{plist_name} ProgramArguments #{opt_bin}/ssdb-server #{etc}/ssdb.conf RunAtLoad WorkingDirectory #{var} StandardErrorPath #{var}/log/ssdb.log StandardOutPath #{var}/log/ssdb.log EOS end test do pid = fork do Signal.trap("TERM") do system("#{bin}/ssdb-server -d #{HOMEBREW_PREFIX}/etc/ssdb.conf") exit end end sleep(3) Process.kill("TERM", pid) end end