require 'formula' class Elasticsearch < Formula url 'https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.17.5.tar.gz' homepage 'http://www.elasticsearch.org' md5 '6bbd4f69fd0addcab56e3f8315e9d837' def install # Remove Windows files rm_f Dir["bin/*.bat"] # Install everything directly into folder prefix.install Dir['*'] # Make sure we have support folders in /usr/var %w( run data/elasticsearch log ).each { |path| (var+path).mkpath } # Put basic configuration into config file inreplace "#{prefix}/config/elasticsearch.yml" do |s| s << <<-EOS.undent cluster: name: elasticsearch path: logs: #{var}/log data: #{var}/data EOS end # Write PLIST file for `launchd` (prefix+'org.elasticsearch.plist').write startup_plist end def caveats <<-EOS.undent If this is your first install, automatically load ElasticSearch on login with: mkdir -p ~/Library/LaunchAgents ln -nfs #{prefix}/org.elasticsearch.plist ~/Library/LaunchAgents/ launchctl load -wF ~/Library/LaunchAgents/org.elasticsearch.plist If this is an upgrade and you already have the org.elasticsearch.plist loaded: launchctl unload -w ~/Library/LaunchAgents/org.elasticsearch.plist ln -nfs #{prefix}/org.elasticsearch.plist ~/Library/LaunchAgents/ launchctl load -wF ~/Library/LaunchAgents/org.elasticsearch.plist To stop the ElasticSearch daemon: launchctl unload -wF ~/Library/LaunchAgents/org.elasticsearch.plist To start ElasticSearch manually: elasticsearch -f -D es.config=#{prefix}/config/elasticsearch.yml See the #{prefix}/config/elasticsearch.yml file for configuration. You'll find the ElasticSearch log here: #{var}/log/elasticsearch.log The folder with all the data is here: #{var}/data/elasticsearch You should see ElasticSearch running: open http://localhost:9200/ EOS end def startup_plist <<-PLIST.undent KeepAlive Label org.elasticsearch ProgramArguments #{bin}/elasticsearch -f -D es.config=#{prefix}/config/elasticsearch.yml -p #{var}/run/elasticsearch.pid RunAtLoad UserName #{`whoami`.chomp} WorkingDirectory #{var} StandardErrorPath #{var}/log/elasticsearch.log StandardOutPath #{var}/log/elasticsearch.log PLIST end end