1

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

3 Answers 3

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/>
6
  • In response to your questions. When I run it by hand it does exit after starting the daemon and shows the shell prompt. I liked the solution you proposed. Either run it as daemon directly or change the starter script. How should I set it to run as daemon directly? Not familiar with setting up daemons.
    – java_dude
    Aug 27, 2013 at 6:26
  • I'm not familiar enough with activemq to know. What I'd recommend is looking at the starter script to see what it does. If it just runs a program in the background (i.e. with & at the end of the command), just do that. If it does more than that, you may have to write your own script that does the other bits, then runs the actual daemon in the foreground. BTW, it'll probably also create and/or check a PID file so it can tell if the daemon's already running; you can ignore this bit, as launchd makes that unnecessary. Aug 27, 2013 at 13:12
  • If I'm reading the activepq docs right, the actual daemon may be /Library/ActiveMQ/bin/activemq - if so, all you'd need to do is have that path as the only element in ProgramArguments. Aug 27, 2013 at 13:19
  • I tried by removing the start argument from plist and it failed to load. So it seems I need to have the location of activemq and the argument start to successfully execute plist.
    – java_dude
    Aug 28, 2013 at 17:49
  • Is there an executable at /Library/ActiveMQ/bin/activemq (note: no /macosx/ in that path)? If so, try running that. Also, take a look at the /Library/ActiveMQ/bin/macosx/activemq script and see what it actually does. Aug 28, 2013 at 18:03
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 
3
  • Well the load command works. Not sure what was the difference between my load command and your load command. But anyhow I can see ActiveMQ started. So in short this solved my problem. BTW I checked, unload does not stop ActiveMQ. Any ideas on that?
    – java_dude
    Aug 26, 2013 at 9:27
  • @LCC From launchctl unload man page : This will also stop the job if it is running. Aug 26, 2013 at 9:58
  • @Parag You are right. I removed my comments. Unloading will send SIGTERM. Should the job catch this signal launchd will send SIGKILL after ExitTimeOut seconds to bring it down. I assume that activemq is spawning a child process in a way that killing its parent does not affect its operation.
    – LCC
    Aug 28, 2013 at 3:52
0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.