Apache Commons Daemon consists of two parts for managing daemon processes on both Unix and Windows systems. The first of two is a C library for interacting with the operating system and the second part is a Java API for interacting with the daemon. On Windows systems the C part is called Procrun and we’ll be using it to create a service wrapper for Apache ActiveMQ. Procrun consists of two executables prunsrv.exe and prunmgr.exe. The later is GUI application to manage the windows service after it has been installed.
I was lead to Procrun while setting up ActiveMQ on Windows 2008 server 64-bit. ActiveMQ ships with the popular java service wrapper by Tanuki Software but the community version of the wrapper isn’t available for 64-bit versions of windows.
If you do go ahead and install the service wrapper that ships with ActiveMQ you’ll see this warning in the wrapper.log file after starting the ActiveMQ service.
WARNING - Unable to load the Wrapper's native library 'wrapper.dll'.
The file is located on the path at the following location but
could not be loaded:
C:\JAVA\apache-activemq-5.3.1\bin\win32\..\..\bin\win32\wrapper.dll
Please verify that the file is readable by the current user
and that the file has not been corrupted in any way.
One common cause of this problem is running a 32-bit version
of the Wrapper with a 64-bit version of Java, or vica versa.
This is a 64-bit JVM.
Reported cause:
C:\JAVA\apache-activemq-5.3.1\bin\win32\wrapper.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
System signals will not be handled correctly.
I’m assuming you have already downloaded and extracted ActiveMQ.
Download native binaries
First, you’ll need to download Commons Daemon native binaries and then extract the zip file.
Copy and Rename
Navigate to the folder specific to the architecture of the OS your installing the service on, in my case it was amd64. Copy prunsrv.exe to ACTIVEMQ_HOME/bin and then rename the .exe to ActiveMQ.exe. This file is the service wrapper executable Windows will launch when the OS boots up. Next is to copy prunmgr.exe to ACTIVEMQ_HOME/bin and rename that to ActiveMQw.exe. Whatever name you choose for renaming prunsrv.exe to, make sure to rename prunmgr.exe to the same name with ‘w’ appended. This is the executable to configure and manage the windows service after it has been installed.
Install Service
Open a command prompt in Administrator mode by right-clicking and selecting “Run as Administrator”, this may only be specific to Server 2008. Navigate to ACTIVEMQ_HOME\bin where you copied the executables to. Run the following command substituting the path of your installation of ActiveMQ:
C:\Java\apache-activemq-5.4.1\bin>ActiveMQ.exe //IS//ActiveMQ \ --DisplayName="Apache ActiveMQ" \ --Description="Apache ActiveMQ Java Messaging Server" \ --Startup=auto \ --LogPath=C:\Java\apache-activemq-5.4.1\logs \ --LogLevel=INFO \ --LogPrefix=activemq-daemon \ --StdOutput=auto \ --StdError=auto \ --StartPath=C:\Java\apache-activemq-5.4.1 \ --StartClass=org.apache.activemq.console.Main \ --StartMethod=main \ --StartParams=start \ --StartMode=jvm \ --StopPath=C:\Java\apache-activemq-5.4.1 \ --StopClass=org.apache.activemq.console.Main \ --StopMethod=main \ --StopParams=shutdown \ --StopMode=jvm \ --Jvm=C:\Java\jdk1.6.0_18\jre\bin\server\jvm.dll \ --Classpath=C:\Java\apache-activemq-5.4.1\bin\run.jar \ --JvmOptions=-Xmx512M \ ++JvmOptions=-Dorg.apache.activemq.UseDedicatedTaskRunner=true \ ++JvmOptions=-Djava.util.logging.config.file=logging.properties \ ++JvmOptions=-Dactivemq.home=C:\Java\apache-activemq-5.4.1 \ ++JvmOptions=-Dactivemq.base=C:\Java\apache-activemq-5.4.1 \ ++JvmOptions=-Dactivemq.classpath=C:\Java\apache-activemq-5.4.1\conf \ ++JvmOptions=-Dcom.sun.management.jmxremote.port=9004 \ ++JvmOptions=-Dcom.sun.management.jmxremote.authenticate=false \ ++JvmOptions=-Dcom.sun.management.jmxremote.ssl=false
The above command should get you 90% of the way there to a fully configured ActiveMQ windows service. The last 10% of configuration may be easier with the GUI in a trial and error scenario.
GUI
Launch the service manager (the executable you renamed ending with ‘w’) in Administrator mode. Below are the screenshots of each of the tabs in the service manager of fully configured ActiveMQ windows service.






UPDATE:
The above screenshot of the shutdown tab is misconfigured, use these as the arguments instead adjusting the jmx port if needed:
stop --all --jmxurl service:jmx:rmi:///jndi/rmi://localhost:9004/jmxrmi

November 9th, 2010 5:55 am
Works fine on Windows 2008 R2.
I did have to join all lines of the install command to a single line.
You can uninstall the service using
C:\Java\apache-activemq-5.4.1\bin>ActiveMQ.exe //DS//ActiveMQ
January 26th, 2011 2:11 pm
There is a patch to make activemq interact with commons daemon nicer:
https://issues.apache.org/jira/browse/AMQ-2968
April 21st, 2011 1:29 am
Easy to go install and start service.
June 29th, 2011 11:33 am
We are seeing the following error when shutting down the application:
Error 109: The pipe has been closed.
Any idea how to address this?
This is when using the start up/shutdown method of JVM.
September 16th, 2011 5:06 am
It was nice information.
But as I download the binary ex(commons-daemon-1.0.6-bin-windows.zip), after extracting it i dint find procrun.exe in that.
It has
folder called apidocs
commons-daemon-1.0.6 jar file
commons-daemon-1.0.6-javadoc jarfile
commons-daemon-1.0.6-sources jar file.
Where can I get that.
September 16th, 2011 7:55 am
Try this link (random mirror site): http://www.takeyellow.com/apachemirror//commons/daemon/binaries/windows/
You should see a file named: commons-daemon-1.0.7-bin-windows.zip
Hope that helps.
September 21st, 2011 10:46 pm
Great article! Thank you for posting this.
January 4th, 2012 1:10 am
Excellent, running on Windows Server 2008 R2.
Used the prunsrv.exe in the amd64 directory.
Very clear and easy to follow guide, thank you.
Saved me hours.
January 11th, 2012 10:57 am
I was able to install ActiveMQ as a service using the instructions in this article, however when I start it up via the Service control panel I get
Windows could not start the ActiveMQ on the local computer. For more information, review the System Event Log.
When I check the Event Log I see
The ActiveMQ service terminated with service-specific error The operation completed successfully..
I think this may be related to my architecture. I’m running Windows server 2008 R2, my processers are 64 bit Intel Xeon. I did not see that architecture included in the commons-daemon package. When I installed, I used the generic ‘prunsrv.exe’ file instead of the amd64/prunsrv.exe, or the ia64/prunsrv.exe – I received errors when I tried to use these exe files during installation, and was only able to install using the generic prunsrv.exe.
Is there a way to get this to work with my architecture? or did I miss anything?
February 15th, 2012 5:43 am
To run as a service, of course you need to double click on InstallService batch file which is under the win32 folder.