Search code examples
linuxhazelcast

Hazelcast 4.2 standalone as a linux service


I have Hazelcast 4.2 runs in a linux server in a standalone mode by running the following files in background:

hazelcast core : bin/start.sh

hazelcast management center : management-center/bin/start.sh

I am looking for a way to make Hazelcast and management center runs as a Linux service using the start.sh files in order to make it easier to run and stop


Solution

  • I've created few scripts to show how could a Hazelcast IMDG systemd service look like. Find it here: https://github.com/kwart/hazelcast-linux-service

    In the heart of the solution is service script /etc/systemd/system/hazelcast.service:

    [Unit]
    Description=Hazelcast IMDG
    After=syslog.target network.target
    Before=httpd.service
    
    [Service]
    EnvironmentFile=-/etc/hazelcast/hazelcast.conf
    User=hazelcast
    ExecStart=/opt/hazelcast/bin/start.sh
    StandardOutput=journal
    
    [Install]
    WantedBy=multi-user.target
    

    Creating /etc/hazelcast with config files (hazelcast.conf and hazelcast.xml) is optional, but it can be handy to have the possibility to tweak the config on the standard location.

    The custom hazelcast.xml just enables basic REST endpoints.

    <hazelcast xmlns="http://www.hazelcast.com/schema/config"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.hazelcast.com/schema/config
               http://www.hazelcast.com/schema/config/hazelcast-config-4.2.xsd">
        <network>
            <rest-api enabled="true"/>
        </network>
    </hazelcast>
    

    The hazelcast.conf can set java options and the path to the custom hazelcast.xml.

    JAVA_OPTS=-Dhazelcast.config=/etc/hazelcast/hazelcast.xml
    JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
    MIN_HEAP_SIZE=1g
    MAX_HEAP_SIZE=1g
    

    Edit 2021-04-01 A similar approach can be used for the Management Center. A simple service file /etc/systemd/system/hazelcast-mc.service could look like:

    [Unit]
    Description=Hazelcast Management Center
    After=syslog.target network.target
    Before=httpd.service
    
    [Service]
    User=hazelcast
    ExecStart=/opt/hazelcast-mc/bin/start.sh
    StandardOutput=journal
    
    [Install]
    WantedBy=multi-user.target