DX Application Performance Management

 View Only

Running APM extensions as a Windows Service 

Dec 02, 2014 07:59 PM

Unfortunately not all CA APM extensions come with an installer that automatically registers it as a Windows service. But you probably want your EPAgents, CloudMonitor integration, etc. running all the time and automatically restarted if the server goes down.

 

While setting up a daemon under Linux is relatively straightforward (and probably most APM environments are running on Linux or Unix systems) you need other tools and experience to do this under Windows.

 

After some experimenting I decided to go with Apache Commons Daemon. Why? It's open source and works relatively well.

 

commons-logo.png

Relatively means: you have to figure out all the correct parameters . A description can be found here but it took me some experimenting. Therefore I wrote it down for me to remember and to make your life with APM a little easier:

  • Download commons-daemon from the Apache download site
  • Extract it to the same folder as the CA APM extension (in my case APM Integration Pack for CloudMonitor)
  • Run the following commands (or copy & paste it into a file, e.g. service.cmd, and run that):


SETLOCAL

SET COMMAND=install

SET SERVICE_NAME=APMCMINT

SET DISPLAY_NAME="CA APM Integration Pack for CloudMonitor"

SET DESCRIPTION="Integrates CA CloudMonitor into CA APM"

SET CLASSPATH="APMCloudMonitor.jar;.\lib;.\conf"

SET STARTPATH="C:\Program Files\CA APM\APMIntegrationPackForCloudMonitoring9.6.0.0\CloudMon"

SET STARTCLASS=com.wily.apm.cloudmonitor.CloudMonitorAgent

IF NOT DEFINED %JAVA_HOME% SET JAVA_HOME="C:\Program Files\CA APM\APMIntegrationPackForCloudMonitoring9.6.0.0\jre"

 

prunsrv.exe %COMMAND% %SERVICE_NAME% --Startup=auto --DisplayName=%DISPLAY_NAME% --Description=%DESCRIPTION% --Classpath=%CLASSPATH% --StartPath=%STARTPATH% --StartMode=Java --StopMode=Java --StartClass=%STARTCLASS% --JavaHome=%JAVA_HOME%

ENDLOCAL

 

  • Start the service using from the Windows Services management console, by running prunsrv.exe //RS/<service name> or by typing "NET START <service name" in a command prompt.
  • Check the extension log files, the service log in %SystemRoot%\System32\LogFiles\Apache and your APM Webview/Workstation if the extension is running successfully.

 

Again, the parameters are described here but I'll explain them right here:

--Startup=auto: you can also use manual (which is the default) but you want to run the service automatically, don't you?

--DisplayName=%DISPLAY_NAME%: this name is displayed in the Services view

--Description=%DESCRIPTION%: this is the description that is displayed in the Services vie

--Classpath=%CLASSPATH%: this is obviously the Java classpath (relative to the StartPath) and you will probably get it wrong the first time Believe me!

--StartPath=%STARTPATH%: this is the working directory for your service. Relative paths are relative to this - sounds odd somehow!

--StartMode=Java: this worked for me. There are also other modes, see description.

--StopMode=Java: see above.

--StartClass=%STARTCLASS%. Like the %CLASSPATH% you probably have to look it up in the .bat file provided by CA Technologies to start the extension.

--JavaHome=%JAVAHOME%

 

When presented this way it is kind of obvious and self-explanatory but have fun figuring it out on your own?

 

Are you using commons-daemon, too? Or other tools? What is you experience with setting up java as a Windows service?

Statistics
0 Favorited
1 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Aug 06, 2018 12:36 PM

Just to update everyone looking at this post, the new APM 10.7 Infrastructure Agent comes with Tanuki Java Service Wrapper and its own JRE so there's no need for additional work to set it up.

Jan 16, 2015 08:38 AM

Hi,

 

Thank you, will definitely add this advice to my script. I added this to our company blog at Running CA Introscope EPAgent as Windows Service (a.k.a. running a Java application as Windows Service) - NovaTec Blog

 

Cheers,

Stefan

Jan 02, 2015 09:49 PM

Hi Hiko,

 

thanks for the advice for using setlocal. I also added a check for the default JAVA_HOME to my script above. Anyone who is familiar with batch scripts on windows can enhance the script to take parameters, ....

Jan 02, 2015 08:26 PM

I'm not sure if you did so on your script, but you should also use "setlocal" and "endlocal" at the beginning and end of your script to ensure they do not alter your default OS configuration.

Dec 18, 2014 09:52 AM

Hi,

 

I managed to build the same for an EPAgent and thought I share it. So what I had real problem with is shutting down the epagent. So I called java.lang.System.exit() explicitly. This script expects prunsrv to be added to the root of the epagent installation.

 

Cheers,

Stefan

 

 

SET COMMAND=install

SET SERVICE_NAME=servicename

SET DISPLAY_NAME="some display name"

SET DESCRIPTION="a description"

SET CLASSPATH=".\ext;.\lib\Agent.jar;.\lib\EPAgent.jar;.\conf"

SET STARTPATH="C:/path/to/epagent"

SET STARTCLASS=com.wily.introscope.api.IntroscopeEPAgent

SET STOP_CLASS=java.lang.System

SET STOP_METHOD=exit

SET STOP_PARAMS=0

 

REM Set this if JAVA HOME is not found! and add --JavaHome=%JAVAHOME% to prunsrv call.

REM SET JAVAHOME="..."

 

sc delete %SERVICE_NAME%

prunsrv.exe %COMMAND% %SERVICE_NAME% --Startup=auto --DisplayName=%DISPLAY_NAME% --Description=%DESCRIPTION% --Classpath=%CLASSPATH% --StartPath=%STARTPATH% --StartMode=jvm --StopMode=jvm --StartClass=%STARTCLASS%  --StopClass=%STOP_CLASS% --StopMethod=%STOP_METHOD% ++StopParams=%STOP_PARAMS%

sc start %SERVICE_NAME%

Dec 03, 2014 08:50 AM

there is also one missing feature that commons-daemon has over Tanuki is that you can set the (unix) daemon user to a no-shell technical user.

I really would like to know why Tanuki does not support that...

Dec 02, 2014 11:28 PM

Awesome!

 

For any standalone Java apps, like EPA, I use the Tanuki Java Service Wrapper (Tanuki Software Ltd. - Java Service Wrapper).

Many of our products use this, but the free/OSS version is only for 32-bit JREs.

 

Now I'll have a new piece of software to play around with! Thanks!

Related Entries and Links

No Related Resource entered.