Skip to content

Instantly share code, notes, and snippets.

@olaf-2
Last active October 27, 2024 02:42
Show Gist options
  • Save olaf-2/ab7f72cb98c8b24a50a7f2b563221f6e to your computer and use it in GitHub Desktop.
Save olaf-2/ab7f72cb98c8b24a50a7f2b563221f6e to your computer and use it in GitHub Desktop.
Install Apache Ignite as a systemd service

Install Apache Ignite as a systemd service

Create a user for running Apache Ignite.

sudo useradd -s /usr/sbin/nologin -m ignite

Create a folder for the configuration files and the data folder for Apache Ignite Native Persistence.

sudo -u ignite mkdir -p /home/ignite/apache-ignite-config /home/ignite/apache-ignite-data

Download the Apache Ignite binaries. Please use a mirror from https://www.apache.org/dyn/closer.cgi and download the ZIP package from [MIRROR_URL]/ignite/2.7.0/apache-ignite-2.7.0-bin.zip, e.g. in Germany:

sudo -u ignite wget http://ftp.halifax.rwth-aachen.de/apache/ignite/2.7.0/apache-ignite-2.7.0-bin.zip -O /home/ignite/apache-ignite-2.7.0-bin.zip

Unzip it.

sudo -u ignite unzip -d /home/ignite/ /home/ignite/apache-ignite-2.7.0-bin.zip

Remove the ZIP file after successful extraction

sudo -u ignite rm /home/ignite/apache-ignite-2.7.0-bin.zip

Create a link to a generic folder without the version number.

sudo -u ignite ln -s /home/ignite/apache-ignite-2.7.0-bin /home/ignite/apache-ignite-bin

Create a small shell script to start Apache Ignite. Just copy and paste everything into the console.

cat << "EOF" | sudo -u ignite tee /home/ignite/startIgnite.sh
#!/bin/bash
IGNITE_HOME=/home/ignite/apache-ignite-bin
export IGNITE_HOME
/home/ignite/apache-ignite-bin/bin/ignite.sh /home/ignite/apache-ignite-config/production-config.xml
EOF

Make the shell script executable.

sudo -u ignite chmod 755 /home/ignite/startIgnite.sh

Put your configuration file into the config folder, e.g. /home/ignite/apache-ignite-config/production-config.xml and specify the work directory for the Apache Ignite Native Persistence data:

<?xml version="1.0" encoding="UTF-8"?>
<beans ...
    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
        ...
        <property name="workDirectory" value="/home/ignite/apache-ignite-data/" />
        ...
    </bean>
</beans>

Create the service unit. Just copy and paste everything into the console.

cat << "EOF" | sudo tee /lib/systemd/system/ignite.service
[Unit]
Description=Apache Ignite Service
After=network.target

[Service]
WorkingDirectory=/home/ignite
User=ignite
PrivateDevices=yes
ProtectSystem=full
Type=simple
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGTERM
TimeoutStopSec=10
ExecStart=/home/ignite/startIgnite.sh
SyslogIdentifier=Ignite
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
Alias=ignite.service
EOF

Every time you create or change something in the service unit file you need to reload the service unit

sudo systemctl daemon-reload

Enable the service.

sudo systemctl enable ignite.service

Almost done. Start the service,

sudo service ignite start

and check the logs

sudo journalctl -u ignite -f

Congrats. Now you have installed Apache Ignite as a systemd service which will start automatically after a reboot or crash. Since you have created an alias for the service, you will be able to work with it in the future as follows:

sudo service ignite start|stop|restart|status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment