Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hazelcast server as a linux service

Tags:

hazelcast

How to run hazelcast server as a linux service in production environments ?

java -server -cp hazelcast.jar com.hazelcast.examples.StartServer

StartServer runs the server with outputs to std terminal, what's the easiest way to run it as a linux service and write logs to a file & how do I specify min and max memory allocation for Hazelcast.

I have to set it up as a service in an EC2 instance and bundle it. When EC2 autoscaling starts an instance, hazelcast server will start and join the cluster.

Thanks

like image 778
Santhosh S Avatar asked Jan 09 '14 11:01

Santhosh S


People also ask

What is Hazelcast platform?

Hazelcast is a streaming and memory-first application platform for fast, stateful, data-intensive workloads on-premises, at the edge or as a fully managed cloud service.

What is Hazelcast cluster?

What Is Hazelcast? Hazelcast is a distributed In-Memory Data Grid platform for Java. The architecture supports high scalability and data distribution in a clustered environment. It supports the auto-discovery of nodes and intelligent synchronization. Hazelcast is available in different editions.


1 Answers

To use Hazelcast as a service you just need to write a shell/bash script that starts and stops the java application. Then for controlling your Hazelcast configuration you need to pass in the system property hazelcast.config with the path to the file which contains the hazelcast.xml configuration.

Moreover, if you want to have custom logging you can include the JAR files (for log4j2, for example) and set the system property log4j.configurationFile and the path to the XML/JSON file with the logging configuration. Do not forget to set the property hazelcast.logging.type to the according type in your hazelcast config.

As an example code, here you have a really simple bash script for doing what you want. I have not tested it and it is just something to guide you:

#!/bin/bash

function start {
   cd /opt/hazelcast
   rm -f /opt/hazelcast/hazelcast.pid
   javaCmd = "/my/java/home/bin/java -server -cp hazelcast.jar:apache-log4j-2.0-beta9.jar -Dhazelcast.config=/opt/hazelcast/hazelcast.xml -Dlog4j.configurationFile=/opt/hazelcast/log4j2.xml com.hazelcast.examples.StartServer"
   cmd="nohup $javaCmd >> /opt/hazelcast/service.log 2>&1 & echo \$! >/opt/hazelcast/hazelcast.pid"
   su -c "$cmd"
   return 0; }


function stop {
   pid="$(</opt/hazelcast/hazelcast.pid)"
   kill -s KILL $pid || return 1
   return 0; }


function main {
   RETVAL=0
   case "$1" in
      start)                                               
         start
         ;;
      stop)                                                
         stop
         ;;
      *)
         echo "Usage: $0 {start|stop}"
         exit 1
         ;;
      esac
   exit $RETVAL
}


main $1
like image 119
hveiga Avatar answered Sep 21 '22 20:09

hveiga