2010-04-09 13:34:11 +00:00
|
|
|
require 'formula'
|
|
|
|
|
|
|
|
class Elasticsearch < Formula
|
2011-05-13 08:21:58 +00:00
|
|
|
homepage 'http://www.elasticsearch.org'
|
2013-11-13 13:35:46 +00:00
|
|
|
url 'https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.7.tar.gz'
|
|
|
|
sha1 '6cdfe366f3496b587bf440e153567d635ab64559'
|
2013-04-30 01:26:44 +00:00
|
|
|
|
2013-09-21 23:33:42 +00:00
|
|
|
head do
|
|
|
|
url 'https://github.com/elasticsearch/elasticsearch.git'
|
|
|
|
depends_on 'maven'
|
|
|
|
end
|
2011-01-13 19:21:49 +00:00
|
|
|
|
2011-10-02 20:45:20 +00:00
|
|
|
def cluster_name
|
|
|
|
"elasticsearch_#{ENV['USER']}"
|
|
|
|
end
|
|
|
|
|
2011-04-25 11:23:26 +00:00
|
|
|
def install
|
2013-01-01 18:33:06 +00:00
|
|
|
if build.head?
|
|
|
|
# Build the package from source
|
|
|
|
system "mvn clean package -DskipTests"
|
|
|
|
# Extract the package to the current directory
|
|
|
|
system "tar --strip 1 -xzf target/releases/elasticsearch-*.tar.gz"
|
|
|
|
end
|
|
|
|
|
2011-04-25 11:23:26 +00:00
|
|
|
# Remove Windows files
|
|
|
|
rm_f Dir["bin/*.bat"]
|
2012-12-30 14:09:45 +00:00
|
|
|
|
|
|
|
# Move libraries to `libexec` directory
|
2011-11-17 00:09:36 +00:00
|
|
|
libexec.install Dir['lib/*.jar']
|
2012-12-30 14:09:45 +00:00
|
|
|
(libexec/'sigar').install Dir['lib/sigar/*.{jar,dylib}']
|
2011-01-13 19:21:49 +00:00
|
|
|
|
2012-12-30 14:09:45 +00:00
|
|
|
# Install everything else into package directory
|
2011-04-25 11:23:26 +00:00
|
|
|
prefix.install Dir['*']
|
|
|
|
|
2013-01-01 18:33:06 +00:00
|
|
|
# Remove unnecessary files
|
2013-01-04 17:28:57 +00:00
|
|
|
rm_f Dir["#{lib}/sigar/*"]
|
2013-01-01 18:33:06 +00:00
|
|
|
if build.head?
|
|
|
|
rm_rf "#{prefix}/pom.xml"
|
|
|
|
rm_rf "#{prefix}/src/"
|
|
|
|
rm_rf "#{prefix}/target/"
|
|
|
|
end
|
|
|
|
|
2011-10-02 20:45:20 +00:00
|
|
|
# Set up ElasticSearch for local development:
|
2011-04-25 11:23:26 +00:00
|
|
|
inreplace "#{prefix}/config/elasticsearch.yml" do |s|
|
2011-10-02 20:45:20 +00:00
|
|
|
# 1. Give the cluster a unique name
|
|
|
|
s.gsub! /#\s*cluster\.name\: elasticsearch/, "cluster.name: #{cluster_name}"
|
|
|
|
|
|
|
|
# 2. Configure paths
|
2012-12-30 14:09:45 +00:00
|
|
|
s.sub! "# path.data: /path/to/data", "path.data: #{var}/elasticsearch/"
|
|
|
|
s.sub! "# path.logs: /path/to/logs", "path.logs: #{var}/log/elasticsearch/"
|
|
|
|
s.sub! "# path.plugins: /path/to/plugins", "path.plugins: #{var}/lib/elasticsearch/plugins"
|
2012-06-23 14:58:10 +00:00
|
|
|
|
|
|
|
# 3. Bind to loopback IP for laptops roaming different networks
|
|
|
|
s.gsub! /#\s*network\.host\: [^\n]+/, "network.host: 127.0.0.1"
|
2011-04-25 11:23:26 +00:00
|
|
|
end
|
|
|
|
|
2011-11-18 21:22:45 +00:00
|
|
|
inreplace "#{bin}/elasticsearch.in.sh" do |s|
|
2012-12-30 14:09:45 +00:00
|
|
|
# Configure ES_HOME
|
|
|
|
s.sub! /#\!\/bin\/sh\n/, "#!/bin/sh\n\nES_HOME=#{prefix}"
|
|
|
|
# Configure ES_CLASSPATH paths to use libexec instead of lib
|
2011-11-17 00:09:36 +00:00
|
|
|
s.gsub! /ES_HOME\/lib\//, "ES_HOME/libexec/"
|
|
|
|
end
|
|
|
|
|
2011-11-23 22:40:12 +00:00
|
|
|
inreplace "#{bin}/plugin" do |s|
|
2012-12-30 14:09:45 +00:00
|
|
|
# Add the proper ES_CLASSPATH configuration
|
2013-01-04 17:28:57 +00:00
|
|
|
s.sub! /SCRIPT="\$0"/, %Q|SCRIPT="$0"\nES_CLASSPATH=#{libexec}|
|
2012-12-30 14:09:45 +00:00
|
|
|
# Replace paths to use libexec instead of lib
|
|
|
|
s.gsub! /\$ES_HOME\/lib\//, "$ES_CLASSPATH/"
|
2011-11-23 22:40:12 +00:00
|
|
|
end
|
2011-01-13 19:21:49 +00:00
|
|
|
end
|
|
|
|
|
2013-05-25 13:47:02 +00:00
|
|
|
def post_install
|
|
|
|
# Make sure runtime directories exist
|
|
|
|
(var/"elasticsearch/#{cluster_name}").mkpath
|
|
|
|
(var/"log/elasticsearch").mkpath
|
|
|
|
(var/"lib/elasticsearch/plugins").mkpath
|
|
|
|
end
|
|
|
|
|
2012-11-25 15:06:41 +00:00
|
|
|
def caveats; <<-EOS.undent
|
2012-12-30 14:09:45 +00:00
|
|
|
Data: #{var}/elasticsearch/#{cluster_name}/
|
|
|
|
Logs: #{var}/log/elasticsearch/#{cluster_name}.log
|
|
|
|
Plugins: #{var}/lib/elasticsearch/plugins/
|
2011-04-25 11:23:26 +00:00
|
|
|
EOS
|
|
|
|
end
|
2011-01-13 19:21:49 +00:00
|
|
|
|
2012-11-25 15:06:41 +00:00
|
|
|
plist_options :manual => "elasticsearch -f -D es.config=#{HOMEBREW_PREFIX}/opt/elasticsearch/config/elasticsearch.yml"
|
|
|
|
|
|
|
|
def plist; <<-EOS.undent
|
2011-04-25 11:23:26 +00:00
|
|
|
<?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>
|
2011-12-31 05:56:52 +00:00
|
|
|
<string>#{plist_name}</string>
|
2011-04-25 11:23:26 +00:00
|
|
|
<key>ProgramArguments</key>
|
|
|
|
<array>
|
2011-12-31 22:13:31 +00:00
|
|
|
<string>#{HOMEBREW_PREFIX}/bin/elasticsearch</string>
|
2011-04-25 11:23:26 +00:00
|
|
|
<string>-f</string>
|
|
|
|
<string>-D es.config=#{prefix}/config/elasticsearch.yml</string>
|
|
|
|
</array>
|
2012-03-22 04:02:10 +00:00
|
|
|
<key>EnvironmentVariables</key>
|
|
|
|
<dict>
|
|
|
|
<key>ES_JAVA_OPTS</key>
|
|
|
|
<string>-Xss200000</string>
|
|
|
|
</dict>
|
2011-04-25 11:23:26 +00:00
|
|
|
<key>RunAtLoad</key>
|
|
|
|
<true/>
|
|
|
|
<key>WorkingDirectory</key>
|
|
|
|
<string>#{var}</string>
|
|
|
|
<key>StandardErrorPath</key>
|
2011-10-02 20:45:20 +00:00
|
|
|
<string>/dev/null</string>
|
2011-04-25 11:23:26 +00:00
|
|
|
<key>StandardOutPath</key>
|
2011-10-02 20:45:20 +00:00
|
|
|
<string>/dev/null</string>
|
2011-04-25 11:23:26 +00:00
|
|
|
</dict>
|
|
|
|
</plist>
|
2012-11-25 15:06:41 +00:00
|
|
|
EOS
|
2010-04-09 13:34:11 +00:00
|
|
|
end
|
|
|
|
end
|