aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/elasticsearch.rb
blob: 8cbf8c31c53af0eacb137820ee468b69efb66115 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require 'formula'

class Elasticsearch < Formula
  url 'https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.17.7.tar.gz'
  homepage 'http://www.elasticsearch.org'
  md5 '8502edd8a9b7eb43a895eddeaa299850'

  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
    (prefix+'org.elasticsearch.plist').chmod 0644
  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
      <?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>org.elasticsearch</string>
          <key>ProgramArguments</key>
          <array>
            <string>#{bin}/elasticsearch</string>
            <string>-f</string>
            <string>-D es.config=#{prefix}/config/elasticsearch.yml</string>
            <string>-p #{var}/run/elasticsearch.pid</string>
          </array>
          <key>RunAtLoad</key>
          <true/>
          <key>UserName</key>
          <string>#{`whoami`.chomp}</string>
          <key>WorkingDirectory</key>
          <string>#{var}</string>
          <key>StandardErrorPath</key>
          <string>#{var}/log/elasticsearch.log</string>
          <key>StandardOutPath</key>
          <string>#{var}/log/elasticsearch.log</string>
        </dict>
      </plist>
    PLIST
  end
end