Hazelcast server as linux service

How to start hazelcast server as linux service in production environments?

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

StartServer starts the server with outputs to the STD terminal, which is the easiest way to start it as a linux service and write logs to the & amp; how to specify the minimum and maximum memory allocation for Hazelcast.

I need to configure it as a service in an EC2 instance and bind it. When EC2 auto-scan starts the instance, the hazelcast server starts and joins the cluster.

thanks

+6
source share
1 answer

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

In addition, if you want to have your own logging, you can include JAR files (for example, for log4j2) and set the system property log4j.configurationFile and the path to the XML / JSON file with the logging configuration. Remember to set the hazelcast.logging.type property hazelcast.logging.type appropriate type in your hazel configuration.

As an example code, here you have a really simple bash script to execute what you want. I have not tested it, and this is just a guide for 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 
+9
source

All Articles