aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/rabbitmq.rb
blob: a2fc08cd0f473ea7179b04e5e00868db04eed78b (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
99
100
require 'formula'

class Rabbitmq < Formula
  homepage 'http://www.rabbitmq.com'
  url 'http://www.rabbitmq.com/releases/rabbitmq-server/v3.0.0/rabbitmq-server-generic-unix-3.0.0.tar.gz'
  sha1 'a899199afe0bda17676f359789e0fea4ba8caea9'

  depends_on 'erlang'
  depends_on 'simplejson' => :python if MacOS.version == :leopard

  def install
    # Install the base files
    prefix.install Dir['*']

    # Setup the lib files
    (var+'lib/rabbitmq').mkpath
    (var+'log/rabbitmq').mkpath

    # Replace the SYS_PREFIX for things like rabbitmq-plugins
    inreplace (sbin + 'rabbitmq-defaults'), 'SYS_PREFIX=${RABBITMQ_HOME}', "SYS_PREFIX=#{HOMEBREW_PREFIX}"

    # Set the RABBITMQ_HOME in rabbitmq-env
    inreplace (sbin + 'rabbitmq-env'), 'RABBITMQ_HOME="${SCRIPT_DIR}/.."', "RABBITMQ_HOME=#{prefix}"

    # Create the rabbitmq-env.conf file
    rabbitmq_env_conf = etc+'rabbitmq/rabbitmq-env.conf'
    rabbitmq_env_conf.write rabbitmq_env unless rabbitmq_env_conf.exist?

    # Enable the management web UI
    enabled_plugins_path = etc+'rabbitmq/enabled_plugins'
    enabled_plugins_path.write enabled_plugins unless enabled_plugins_path.exist?

    # Extract rabbitmqadmin to sbin
    system "/usr/bin/unzip", "-qq", "-j", "#{prefix}/plugins/rabbitmq_management-#{version}.ez", "rabbitmq_management-#{version}/priv/www/cli/rabbitmqadmin"
    sbin.install 'rabbitmqadmin'

  end

  def caveats
    <<-EOS.undent
    If this is your first install, automatically load on login with:
        mkdir -p ~/Library/LaunchAgents
        cp #{plist_path} ~/Library/LaunchAgents/
        launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}

    If this is an upgrade and you already have the #{plist_path.basename} loaded:
        launchctl unload -w ~/Library/LaunchAgents/#{plist_path.basename}
        cp #{plist_path} ~/Library/LaunchAgents/
        launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}

    Management Plugin enabled by default at http://localhost:15672

    To start rabbitmq-server manually:
        rabbitmq-server
    EOS
  end

  def enabled_plugins
    return <<-EOS.undent
      [rabbitmq_management,rabbitmq_management_visualiser].
    EOS
  end

  def rabbitmq_env
    return <<-EOS.undent
    CONFIG_FILE=#{etc}/rabbitmq/rabbitmq
    NODE_IP_ADDRESS=127.0.0.1
    NODENAME=rabbit@localhost
    EOS
  end

  def startup_plist
    return <<-EOPLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//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>Program</key>
    <string>#{HOMEBREW_PREFIX}/sbin/rabbitmq-server</string>
    <key>RunAtLoad</key>
    <true/>
    <key>UserName</key>
    <string>#{`whoami`.chomp}</string>
    <key>EnvironmentVariables</key>
    <dict>
      <!-- need erl in the path -->
      <key>PATH</key>
      <string>/usr/local/sbin:/usr/bin:/bin:/usr/local/bin</string>
      <!-- specify the path to the rabbitmq-env.conf file -->
      <key>CONF_ENV_FILE</key>
      <string>#{etc}/rabbitmq/rabbitmq-env.conf</string>
    </dict>
  </dict>
</plist>
    EOPLIST
  end
end