homebrew-core/Formula/webdis.rb
2019-07-12 02:13:25 +08:00

73 lines
2 KiB
Ruby

class Webdis < Formula
desc "Redis HTTP interface with JSON output"
homepage "https://webd.is/"
url "https://github.com/nicolasff/webdis/archive/0.1.7.tar.gz"
sha256 "932e8b2d75ea6093759c4f9a228c34de664a1d41c2ef3aaa57fa61cdc38024a2"
bottle do
cellar :any
sha256 "1a624e8fc6cefbb09e39fa7288354155fb31bab4ab8d820158838aab115b2fd6" => :mojave
sha256 "e8a30bb8af33fbf2f752e52bee6afaff0856fe8c5270fed65267b69e4d7dd954" => :high_sierra
sha256 "164d648013e27d26972d8bdc39fff4a884533aef2a3026c330ecf1b536ff76ea" => :sierra
end
depends_on "libevent"
def install
system "make"
bin.install "webdis"
inreplace "webdis.prod.json" do |s|
s.gsub! "/var/log/webdis.log", "#{var}/log/webdis.log"
s.gsub! /daemonize":\s*true/, "daemonize\":\tfalse"
end
etc.install "webdis.json", "webdis.prod.json"
end
def post_install
(var/"log").mkpath
end
plist_options :manual => "webdis #{HOMEBREW_PREFIX}/etc/webdis.json"
def plist; <<~EOS
<?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>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/webdis</string>
<string>#{etc}/webdis.prod.json</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>WorkingDirectory</key>
<string>#{var}</string>
</dict>
</plist>
EOS
end
test do
begin
server = fork do
exec "#{bin}/webdis", "#{etc}/webdis.json"
end
sleep 0.5
# Test that the response is from webdis
assert_match(/Server: Webdis/, shell_output("curl --silent -XGET -I http://localhost:7379/PING"))
ensure
Process.kill "TERM", server
Process.wait server
end
end
end