Using systemd to run a simple process and keep it up

Short post about using systemd to run a simple process :)

You'll need a service file.

For the most part systemd services are registered in config files stored in /etc/systemd/system/XXX.service

For example, running a minecraft server would look like this:

# /etc/systemd/system/minecraft-server.service
[Unit]
Description=Minecraft Server

[Service]
WorkingDirectory=/root/minecraft-server
ExecStart=/usr/bin/java -Xmx6G -Xms4G -jar /root/minecraft-server/server.jar nogui
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

For extra docs on systemd settings , checkout: https://www.freedesktop.org/software/systemd/man/systemd.directives.html

Load your service intp systemd

systemctl daemon-reload
systemctl enable minecraft-server
systemctl start minecraft-server

Check logs

To check the logs of your systemd service, you can use systemctl, or us journalctl

systemctl status minecraft-server
journalctl -e -u minecraft-server

Cheers!