diff --git a/contrib/systemd/README.md b/contrib/systemd/README.md new file mode 100644 index 00000000..db96629f --- /dev/null +++ b/contrib/systemd/README.md @@ -0,0 +1,49 @@ +# Introduction + +This is a starter systemd unit and associated install instructions, to save new users the time of building up everything +from scratch. + +This was created and works as intended on Ubuntu 22.04 LTS (Jammy Jellyfish) + +# Motivations + +- Save researching time for new users +- Adding common starting point for deployment files for distributions, if, as and when kafdrop gets included into + packaging systems by linux distributions further downstream. + +*Note: I could also contribute packaging information for rpm and deb formats, if that's something that'll be useful.* + +# Installation steps + +***Note: The assumed path of installation ($INSTALLDIR) is `/opt/kafdrop`. If any other path is used, then the service +file needs to be modified to use that path in the `# Paths` commented section.*** + +1. Create the directory `$INSTALLDIR` and download the latest release there. + +2. Create the kafdrop user and group: +``` +systemd-sysusers --inline 'u kafdrop - "KafDrop user" $INSTALLDIR /usr/sbin/nologin' +``` + +3. Copy `start.sh` to `$INSTALLDIR`, edit it to fix the startup parameters and options for your use case, and give it + execute permissions +``` +chmod 755 $INSTALLDIR/start.sh +``` + +4. Copy the `kafdrop.service` file to `$INSTALLDIR` and create a link to it in `/etc/systemd/system` +``` +(cd /etc/systemd/system && ln -s $INSTALLDIR/kafdrop.service) +``` + +5. Refresh systemd runtime configuration. +``` +systemctl daemon-reload +``` + +6. Enable and start service. +``` +systemctl enable kafdrop.service && systemctl start kafdrop.service +``` + +7. Profit!! diff --git a/contrib/systemd/kafdrop.service b/contrib/systemd/kafdrop.service new file mode 100644 index 00000000..1d242a5f --- /dev/null +++ b/contrib/systemd/kafdrop.service @@ -0,0 +1,31 @@ +# Systemd unit file for KafDrop +# Thanks to Kafka users on the internet for the starter template + +[Unit] +Description=KafDrop server +Documentation=https://github.com/obsidiandynamics/kafdrop +Requires=network.target remote-fs.target +After=network.target remote-fs.target kafka.target + +[Service] +Type=simple +ExecStart=/opt/kafdrop/start.sh +SuccessExitStatus=143 +Restart=on-abnormal +# Logging +SyslogIdentifier=kafdrop +# Paths +User=kafdrop +Group=kafdrop +PrivateTmp=yes +# Network service +AmbientCapabilities=CAP_NET_BIND_SERVICE +# Restrict privileges +NoNewPrivileges=true +# paths +WorkingDirectory=/opt/kafdrop +ReadOnlyPaths=/opt/kafdrop +RuntimeDirectory=kafdrop + +[Install] +WantedBy=multi-user.target diff --git a/contrib/systemd/start.sh b/contrib/systemd/start.sh new file mode 100644 index 00000000..5c1b1cae --- /dev/null +++ b/contrib/systemd/start.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# Variables for single point of customization +BOOTSTRAP_SERVER="localhost:9092" +VERSION="4.1.0" +LISTEN_PORT=8080 + +# Running from JAR +exec java --add-opens=java.base/sun.nio.ch=ALL-UNNAMED \ + -jar kafdrop-"${VERSION}".jar \ + --kafka.brokerConnect="${BOOTSTRAP_SERVER}" \ + --server.port=${LISTEN_PORT} --management.server.port=${LISTEN_PORT}