Mac Daemon for ActiveMQ

2019-08-04 00:04发布

问题:

I have tried setting ActiveMQ daemon but have been unsuccessful so far. I can't seem to load ActiveMQ. Not sure what more can I do to make this work? I can start ActiveMQ by running command /Library/ActiveMQ/bin/macosx/activemq start

In the plist

<?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>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>com.apache.activemq</string>
    <key>ProgramArguments</key>
    <array>            
        <string>/Library/ActiveMQ/bin/macosx/activemq</string>
        <string>start</string>
        <string>;</string>
        <string>--stop-cmd</string>
        <string>/Library/ActiveMQ/bin/macosx/activemq</string>
        <string>stop</string>
        <string>;</string>
        <string>--restart-cmd</string>
        <string>/Library/ActiveMQ/bin/macosx/activemq</string>
        <string>restart</string>
        <string>;</string>
        <string>--pid=none</string>
    </array>
    <key>WorkingDirectory</key>
    <string>/Library/ActiveMQ</string>
    <key>ServiceDescription</key>
    <string>ActiveMQ</string>
    <key>StandardErrorPath</key>
    <string>/var/log/activemq.stderr</string>
    <key>StandardOutPath</key>
    <string>/var/log/activemq.stdout</string>
</dict>
</plist>

Result of executing the launchctl command

macosx user$ sudo launchctl load -w /Library/LaunchDaemons/activemq.plist com.apache.activemq: Already loaded

回答1:

Run below command on terminal

 sudo launchctl unload /Library/LaunchDaemons/activemq.plist

or

sudo launchctl remove com.apache.activemq

then

sudo launchctl load -w /Library/LaunchDaemons/activemq.plist 


回答2:

Your .plist file looks wrong in several ways, and this may be causing at least part of the problem. First, the ProgramArguments seems to have a lot of irrelevant junk in it (maybe leftovers from using daemond?) In general, the first argument of ProgramArguments should be the path to the program you want to execute, and the rest should be its arguments. It looks to me like this is all you should have:

<key>ProgramArguments</key>
<array>            
    <string>/Library/ActiveMQ/bin/macosx/activemq</string>
    <string>start</string>
</array>            

Second, that "start" argument makes me think that's not the actual daemon program, but a management script that starts the daemon in the background, then exits. When you run /Library/ActiveMQ/bin/macosx/activemq start by hand, does it exit (i.e. give you a new shell prompt) and leave the daemon running in the background? launchd doesn't expect that, it expects to be running the daemon directly, so that it can monitor it and e.g. restart it if necessary. Here's the typical sequence when you tell launchd to run a starter script, rather than the actual daemon:

  1. launchd runs the starter script.
  2. The starter script runs the daemon in the background, then exits.
  3. launchd sees that the program it was told to run has exited, and thinks to itself "OMG it's crashed! I'd better clean up the mess and restart it!"
  4. In an attempt to "clean up the mess", launchd kills any leftover background processes; in this case, that means it kills the actual daemon.
  5. Since launchd has been told to keep the program alive, it starts a new instance, restarting the whole sequence over and over again.

...Needless to say, this doesn't work very well. If this or something similar is happening, you have two options to fix it:

  • Skip the starter script, and have launchd run the actual daemon directly. This is the better way to do it, because you get launchd's ability to monitor, restart, stop, etc the daemon.
  • Use the starter script, but tell launchd not to panic when it exits. Change KeepAlive to false, and add <key>AbandonProcessGroup</key><true/>


回答3:

I followed the ideas of @Gordon Davisson

but I'm calling activemq console instead activemq start and it is working now.

here the complete plist file:

<?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>/usr/local/Cellar/activemq/5.13.2/bin/activemq</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/Cellar/activemq/5.13.2/bin/activemq</string>
        <string>console</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
    <key>WorkingDirectory</key>
    <string>/usr/local/Cellar/activemq/5.13.2/libexec/data</string>
</dict>
</plist>