Oct 07 2010

Commons Daemon Procrun as a Java Service Wrapper for ActiveMQ

Category: ActiveMQRussell Pitre @ 9:58 pm

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


Oct 04 2010

Up and Running with STk Scheme and Emacs

Category: emacs,UbunutuRussell Pitre @ 10:50 pm

Today I started to watch The Structure and Interpretation of Computer Programs (SICP) course at Academic Earth. Academic Earth provides free access to video courses from top universities like UC Berkeley where this course is taught. The course is based on the popular computer science book Structure and Interpretation of Computer Programs. The professor of the course, Brian Harvey, claims it to be the best computer science book you’ll ever read, not the first time I’ve heard that. The book is available online for free, just Google SCIP.

The purpose of this blog post is to get you up and running quickly with the dialect of scheme the course uses called STk and the emacs editor. My Linux chops are not strong at all so it took me a couple of days of spare time to Google and setup my scheme environment.

I tried my best to capture and list the references I used below at the end of this post.

I’m running a fresh install of 32-bit Ubuntu Server 10.4.

Installing STk

These steps were taken directly from UCB Scheme page here.

First step is to install the Korn shell (ksh) which is required to install STk.

sudo apt-get install ksh

Download STk from UC Berkeley.

wget http://inst.eecs.berkeley.edu/~scheme/precompiled/Linux/STk-4.0.1-ucb1.3.6.i386.rpm

Install Alien.

sudo apt-get install alien

Remove the stk package name conflict between UCB stk and stk the sound processing library.

sudo aptitude remove stk
sudo apt-get upgrade
sudo apt-get dist-upgrade

Run alien to convert the rpm into the debian package format.

sudo alien -d STk-4.0.1-ucb1.3.6.i386.rpm

Install STk using the newly created .deb file.

sudo dpkg -i stk_4.0.1-1_i386.deb

Now you should be able to run the STk interpreter.

stk

Short Introduction to Emacs

The primary motivation for this blog post is this section about Emacs. While watching the first video in the SICP course I noticed the instructor using a split screen text editor and was curious to learn more about it. I will gently introduce basic emacs commands and finish up with showing you how to setup emacs with a split screen. In the top pane we’ll write simple function and in the bottom pane we’ll run the function in “shell” buffer.

Emacs definitely takes some getting use to if you’re not a keyboard jockey, hopefully you can hang in there.

If you don’t have emacs installed, you can install it by running the following command:

sudo apt-get install emacs23

Launch emacs by typing the command:

emacs square.scm

Once emacs is up and running type the following scheme function in the editor.

(define (square x) (* x x))

Save the buffer using the following command.

Ctrl-x, Ctrl-s

You have seem a message that says “Wrote /path/to/square.scm”. Now we want to split the editor into two horizontal windows. One pane will display the scheme function and the other will display a command prompt where we can launch the STk interpreter. In order to accomplish this, we start a new “shell” buffer.

Alt-x, and type "shell" (without the parenthesis)

Next up is to split the window horizontally. This split the window horizontally with the same document in both panes.

Ctrl-x, 2

Now you’ll want to switch focus between the two panes.

Ctrl-x, o  (thats an 'o', not a zero)

Switch focus to the pane you want to view the scheme function in and then type:

Ctrl-x, b

Switch focus to the pane containing the STk interpreter using the Ctrl-x, o command and then load the scheme function.

STk>(load "scheme.scm")

Now that the function is loaded into the interpreter you should be able use the square function.

STk> (square 5)
25
STk>

And there you have it, a split horizontal pane in emacs where you can view both the STk interpreter and the source code of the function.

References

(Installation)

http://inst.eecs.berkeley.edu/~scheme/precompiled/Linux/

http://ubuntuforums.org/showthread.php?t=682432