Hazelcast as Windows ServiceCheck this Github Repo For code
Hazelcast can follow 2 main deployment typology however if you are following a Server - Client Architecture and you want to start a server on a windows node, follow the below steps.
Am using Apache Procrun to expose the Hazelcast as a windows Service
Follow the link to understand more on the same,It is very easy to setup however documentation is little tedious to get a grasp.
Will create a windows service (kind of obvious :) ).
Another Jar to maintain along with the Hazelcast. Since we have a dependency in our self executable jar project, on Hazelcast version upgrade means upgrading the jar as well. (Ideally,it will work even without upgrading assuming the Core Hazelcast API is going to remain the same with the future releases).
Will look for some other options till then will stick to this.
Anyways here are the steps to follow
Creating a Executable Java Wrapper JAR for Hazelcast.
- Download the Source code and Compile the Project.It is a maven project and uses the Apache Maven Shade Plugin in POM. It is disabled now to not include the Dependencies- Hazelcast jar and Log4j jar etc. The Idea is to make procrun pick it up from the class path. IF shade plugin is enabled can create a FAT jar that will have all dependencies packed in one. This will make future releases more tedious as the jar dependencies needs to be upgraded as well.
- Our Idea is to Create a Self Executable Jar File with a start method which will start the server and Stop Method which will stop the Server.
- Once the Compile is successful , Use the "HazelCastService-1.0-SNAPSHOT.jar" Check the Manifest file to make sure it contains this line Main-Class: com.aravind.service.HazelCastService. This entry makes sure the jar is executable.
- In Pom file the versions defined are 1.7 however it will work just fine with 1.8. Hazelcast version also will work fine with Java 1.8.
- Start Method takes the Config file as argument. The Argument is passed into the class by the service created by Procrun.
Setting Up Procrun and Windows Service.
The Scripts Folder contains 2 files
- HazelCastService.bat - This File will create the Service in windows
- Open the File and Modify the locations in the file to point to the right locations on the node. Note: If the Locations contains Space, try enclosing in Double quotes and run again.
- Add the Log4j jar defined in the Class path line to the Folder in which all other jars exist. I usually put both these files in the lib folder of Hazelcast download along with the log4j Jar.
- PR_STARTPARAMS - will take the location of the XML file.
- -Dhazelcast.logging.type=log4j if this is defined dont forget to add the log4j.xml or properties and add that file name to the end of Class Path variable. Best is to add it in same folder as the other jars. If file not added all the things that get logged on to the Console windows will be auto redirected to the lof files specified in the bat file.
- hazelcastinstallsvc.exe //IS//%SERVICE_NAME% - this line will install the windows service
- The Logs can be seen in the folder we specified in the bat file. Note: Might not see the details in Event logs on windows. Always check the defined log file path and file for details.
- hazelcastinstallsvc.exe - this is downloaded from the Procrun downloads page however this is the exe under amd64 folder.
use hazelcastinstallsvc.exe //DS//<SERVICE_NAME> change service name with your service name.
The Solution works with all the JVM parameters and is not that difficult. I feel it is more elegant than relying on the Bat file or using Run time to kill the process from java.
The other thing to note is porting to Linux is also easy using the same apache commons library jsvc.