RabbitMQ没有开始使用launchd

时间:2016-09-24 18:28:03

标签: macos rabbitmq launchd launch-daemon

我使用的是MacPorts生态系统,而rabbitmq-server端口真的很旧,而且它不再起作用了。所以我使用Generic Unix release在Mac OS X Sierra上安装了rabbitmq-server。它有效。

RabbitMQ安装在/usr/local/rabbitmq_server-3.6.5/下,/usr/local/sbin/下的所有可执行文件都有符号链接。

ls -al
total 40
drwxr-xr-x  7 root  wheel  238 Sep 24 19:50 .
drwxr-xr-x  8 root  wheel  272 Sep 24 19:30 ..
lrwxr-xr-x  1 root  wheel   55 Sep 24 19:50 rabbitmq-defaults -> /usr/local/rabbitmq_server-3.6.5/sbin/rabbitmq-defaults
lrwxr-xr-x  1 root  wheel   50 Sep 24 19:50 rabbitmq-env -> /usr/local/rabbitmq_server-3.6.5/sbin/rabbitmq-env
lrwxr-xr-x  1 root  wheel   54 Sep 24 19:50 rabbitmq-plugins -> /usr/local/rabbitmq_server-3.6.5/sbin/rabbitmq-plugins
lrwxr-xr-x  1 root  wheel   53 Sep 24 19:50 rabbitmq-server -> /usr/local/rabbitmq_server-3.6.5/sbin/rabbitmq-server
lrwxr-xr-x  1 root  wheel   49 Sep 24 19:50 rabbitmqctl -> /usr/local/rabbitmq_server-3.6.5/sbin/rabbitmqctl

当我运行RabbitMQ服务器时,一切都按预期工作:

sudo rabbitmq-server
Password:

          RabbitMQ 3.6.5. Copyright (C) 2007-2016 Pivotal Software, Inc.
##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
##  ##
##########  Logs: /usr/local/rabbitmq_server-3.6.5/var/log/rabbitmq/rabbit@MacBookPro.log
######  ##        /usr/local/rabbitmq_server-3.6.5/var/log/rabbitmq/rabbit@MacBookPro-sasl.log
##########
          Starting broker...
completed with 6 plugins.

为了自动启动守护程序,我创建了一个com.rabbitmq.rabbitmq-server.plist文件/usr/local/etc/LaunchDaemons。我还在/Library/LaunchDaemons中为此文件创建了一个符号链接。所有者为root,该群组为wheel

ls -al
total 88
drwxr-xr-x  13 root  wheel   442 Sep 24 19:51 .
drwxr-xr-x+ 61 root  wheel  2074 Sep 23 14:33 ..
lrwxr-xr-x   1 root  wheel   103 Dec 11  2015 com.oracle.java.Helper-Tool.plist -> /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Resources/com.oracle.java.Helper-Tool.plist
lrwxr-xr-x   1 root  wheel    63 Sep 24 19:16 com.rabbitmq.rabbitmq-server.plist -> /usr/local/etc/LaunchDaemons/com.rabbitmq.rabbitmq-server.plist
lrwxr-xr-x   1 root  admin    66 Sep 12 10:04 org.freedesktop.dbus-system.plist -> /opt/local/Library/LaunchDaemons/org.freedesktop.dbus-system.plist
lrwxr-xr-x   1 root  admin    76 Sep 23 16:40 org.macports.OpenSSH.plist -> /opt/local/etc/LaunchDaemons/org.macports.OpenSSH/org.macports.OpenSSH.plist
lrwxr-xr-x   1 root  admin    76 Sep 20 20:43 org.macports.apache2.plist -> /opt/local/etc/LaunchDaemons/org.macports.apache2/org.macports.apache2.plist
lrwxr-xr-x   1 root  admin    80 Sep 13 00:46 org.macports.memcached.plist -> /opt/local/etc/LaunchDaemons/org.macports.memcached/org.macports.memcached.plist
lrwxr-xr-x   1 root  admin    90 Sep 23 16:33 org.macports.mysql56-server.plist -> /opt/local/etc/LaunchDaemons/org.macports.mysql56-server/org.macports.mysql56-server.plist
lrwxr-xr-x   1 root  admin    72 Sep 23 15:17 org.macports.redis.plist -> /opt/local/etc/LaunchDaemons/org.macports.redis/org.macports.redis.plist
lrwxr-xr-x   1 root  admin    74 Sep 23 15:19 org.macports.rsyncd.plist -> /opt/local/etc/LaunchDaemons/org.macports.rsyncd/org.macports.rsyncd.plist
lrwxr-xr-x   1 root  admin    72 Sep 12 18:00 org.macports.slapd.plist -> /opt/local/etc/LaunchDaemons/org.macports.slapd/org.macports.slapd.plist
lrwxr-xr-x   1 root  wheel    84 May 25 03:58 org.macports.supervisord.plist -> /opt/local/etc/LaunchDaemons/org.macports.supervisord/org.macports.supervisord.plist

以下是plist文件内容:

<?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>com.rabbitmq.rabbitmq-server</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/sbin/rabbitmq-server</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>EnvironmentVariables</key>
  <dict>
    <key>PATH</key>
    <string>/usr/local/sbin:/usr/bin:/bin:/usr/local/bin</string>
  </dict>
</dict>
</plist>

当我尝试使用

加载plist文件时
sudo launchctl load -w /Library/LaunchDaemons/com.rabbitmq.rabbitmq-server.plist 

我没有收到任何错误,但守护程序无法启动。我甚至尝试将调试信息添加到plist,但日志不会显示任何错误。 我做错了什么?

1 个答案:

答案 0 :(得分:1)

嗯,这并不容易,但我终于找到了解决方案。

这是最终的com.rabbitmq.rabbitmq-server.plist脚本:

<?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>com.rabbitmq.rabbitmq-server</string>
  <key>ProgramArguments</key>
  <array>
    <string>/opt/local/bin/daemondo</string>
    <string>--label=rabbitmq-server</string>
    <string>--start-cmd</string>
    <string>/usr/local/sbin/rabbitmq-server</string>
    <string>-u</string>
    <string>nobody</string>
    <string>;</string>
    <string>--pid=exec</string>
  </array>
  <key>Disabled</key><true/>
  <key>RunAtLoad</key><true/>
  <key>KeepAlive</key><true/>
  <key>EnvironmentVariables</key>
  <dict>
    <key>HOME</key>
    <string>/usr/local/rabbitmq_server-3.6.5</string>
    <key>PATH</key>
    <string>/usr/local/sbin:/usr/bin:/bin:/usr/local/bin:/opt/local/bin:/opt/local/sbin:/usr/local/rabbitmq_server-3.6.5/sbin</string>
  </dict>
  <key>StandardOutPath</key>
  <string>/var/log/rabbit-launchd.log</string>
  <key>StandardErrorPath</key>
  <string>/var/log/rabbit-launchd-error.log</string>
</dict>
</plist>

我使用了MacPorts中的daemondo来运行rabbitmq-server可执行文件。比我更新了PATH变量。使用StandardErrorPath我已经发现ErLang无法找到可执行的主目录:事实上我得到了这个错误:

erlexec: HOME must be set

所以我已将HOME添加到EnvironmentVariables部分。

如果您在MacPorts上进行中继而不使用Homebrew,则可以使用此脚本使用launchd运行RabbitMQ服务器并安装Generic Unix版本。