Skip to content

Commit 3b181d1

Browse files
authored
Add systemd unit as user contrib (#759)
* Add systemd unit as user contrib Signed-off-by: Samveen <samveen@samveen.in> * Fix minor issues exposed by review and linter run Signed-off-by: Samveen <samveen@samveen.in> --------- Signed-off-by: Samveen <samveen@samveen.in>
1 parent 10017ec commit 3b181d1

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

contrib/systemd/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Introduction
2+
3+
This is a starter systemd unit and associated install instructions, to save new users the time of building up everything
4+
from scratch.
5+
6+
This was created and works as intended on Ubuntu 22.04 LTS (Jammy Jellyfish)
7+
8+
# Motivations
9+
10+
- Save researching time for new users
11+
- Adding common starting point for deployment files for distributions, if, as and when kafdrop gets included into
12+
packaging systems by linux distributions further downstream.
13+
14+
*Note: I could also contribute packaging information for rpm and deb formats, if that's something that'll be useful.*
15+
16+
# Installation steps
17+
18+
***Note: The assumed path of installation ($INSTALLDIR) is `/opt/kafdrop`. If any other path is used, then the service
19+
file needs to be modified to use that path in the `# Paths` commented section.***
20+
21+
1. Create the directory `$INSTALLDIR` and download the latest release there.
22+
23+
2. Create the kafdrop user and group:
24+
```
25+
systemd-sysusers --inline 'u kafdrop - "KafDrop user" $INSTALLDIR /usr/sbin/nologin'
26+
```
27+
28+
3. Copy `start.sh` to `$INSTALLDIR`, edit it to fix the startup parameters and options for your use case, and give it
29+
execute permissions
30+
```
31+
chmod 755 $INSTALLDIR/start.sh
32+
```
33+
34+
4. Copy the `kafdrop.service` file to `$INSTALLDIR` and create a link to it in `/etc/systemd/system`
35+
```
36+
(cd /etc/systemd/system && ln -s $INSTALLDIR/kafdrop.service)
37+
```
38+
39+
5. Refresh systemd runtime configuration.
40+
```
41+
systemctl daemon-reload
42+
```
43+
44+
6. Enable and start service.
45+
```
46+
systemctl enable kafdrop.service && systemctl start kafdrop.service
47+
```
48+
49+
7. Profit!!

contrib/systemd/kafdrop.service

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Systemd unit file for KafDrop
2+
# Thanks to Kafka users on the internet for the starter template
3+
4+
[Unit]
5+
Description=KafDrop server
6+
Documentation=https://github.com/obsidiandynamics/kafdrop
7+
Requires=network.target remote-fs.target
8+
After=network.target remote-fs.target kafka.target
9+
10+
[Service]
11+
Type=simple
12+
ExecStart=/opt/kafdrop/start.sh
13+
SuccessExitStatus=143
14+
Restart=on-abnormal
15+
# Logging
16+
SyslogIdentifier=kafdrop
17+
# Paths
18+
User=kafdrop
19+
Group=kafdrop
20+
PrivateTmp=yes
21+
# Network service
22+
AmbientCapabilities=CAP_NET_BIND_SERVICE
23+
# Restrict privileges
24+
NoNewPrivileges=true
25+
# paths
26+
WorkingDirectory=/opt/kafdrop
27+
ReadOnlyPaths=/opt/kafdrop
28+
RuntimeDirectory=kafdrop
29+
30+
[Install]
31+
WantedBy=multi-user.target

contrib/systemd/start.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
# Variables for single point of customization
4+
BOOTSTRAP_SERVER="localhost:9092"
5+
VERSION="4.1.0"
6+
LISTEN_PORT=8080
7+
8+
# Running from JAR
9+
exec java --add-opens=java.base/sun.nio.ch=ALL-UNNAMED \
10+
-jar kafdrop-"${VERSION}".jar \
11+
--kafka.brokerConnect="${BOOTSTRAP_SERVER}" \
12+
--server.port=${LISTEN_PORT} --management.server.port=${LISTEN_PORT}

0 commit comments

Comments
 (0)