Skip to content

Commit 6582f67

Browse files
committed
pping: Add systemd unit files for running pping
Add some example files for setting up ePPing with systemd. The setup creates "log" files in /var/log/pping and rotates them every minute (appending a date at the time of rotation). Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
1 parent 9ba9e7c commit 6582f67

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
MAX_WAIT_ITER=10
4+
pping_path=${1:-"/var/log/pping/pping.out.json"}
5+
6+
pping_folder=$(dirname "$pping_path")
7+
pping_file=$(basename "$pping_path")
8+
9+
if [[ ! -f "$pping_path" ]]; then
10+
# Nothing to rotate
11+
exit 0
12+
fi
13+
14+
dailyfolder="$pping_folder/$(date -Idate)"
15+
if ! mkdir -p "$dailyfolder"; then
16+
exit 1
17+
fi
18+
19+
newplace="$dailyfolder/$pping_file.$(date -Iseconds)"
20+
if ! mv "$pping_path" "$newplace"; then
21+
exit 1
22+
fi
23+
24+
# Tell ePPing to reopen file
25+
if systemctl is-active --quiet pping.service; then
26+
systemctl reload pping.service
27+
fi
28+
29+
if [[ -f "$newplace" ]]; then
30+
for (( i = 0; i < MAX_WAIT_ITER; i++)); do
31+
if fuser -s "$newplace"; then
32+
sleep 1
33+
else
34+
gzip "$newplace"
35+
exit $?
36+
fi
37+
done
38+
fi
39+
40+
echo "Timed out waiting for $newplace to become unused, unable to compress it" 1>&2
41+
exit 1

pping/systemd-files/pping.service

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[Unit]
2+
Description=ePPing - Passive monitoring of network RTTs
3+
After=network.service
4+
Wants=rotate-pping.timer
5+
6+
# Uncomment below if running with LibreQoS
7+
# After=lqosd.service
8+
9+
[Service]
10+
# Ensure folder for saving output to exists
11+
ExecStartPre=/usr/bin/mkdir -p /var/log/pping
12+
13+
# Rotate any old output first to ensure ePPing can start writing to its intended file
14+
ExecStartPre=/opt/bpf-examples/pping/scripts/rotate-pping-output.sh /var/log/pping/pping.out.json
15+
16+
WorkingDirectory=/opt/bpf-examples/pping
17+
ExecStart=/opt/bpf-examples/pping/pping -i <interface> -l -r 10 -a 10 -F json -w /var/log/pping/pping.out.json
18+
19+
# On systemctl reload, send a SIGHUP to ePPing which causes it to reopen its output file
20+
ExecReload=kill -HUP $MAINPID
21+
22+
Restart=on-failure
23+
RestartSec=60
24+
25+
# Set to whatever maximum memory footprint you can tolerate
26+
# Note, hard-kills the ePPing process without allowing it to clean up. Consider
27+
# running /scripts/cleanup-tc-progs after.
28+
MemoryMax=4G
29+
30+
[Install]
31+
WantedBy=default.target
32+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[Unit]
2+
Description=Rotates the output file from ePPing (pping.service)
3+
4+
[Service]
5+
Type=oneshot
6+
ExecStart=/opt/bpf-examples/pping/scripts/rotate-pping-output.sh /var/log/pping/pping.out.json
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=Rotate ePPing output periodically
3+
PartOf=pping.service
4+
5+
[Timer]
6+
Unit=rotate-pping.service
7+
8+
# Rotate ePPing output every X seconds
9+
OnActiveSec=60
10+
OnUnitActiveSec=60
11+
AccuracySec=1us

0 commit comments

Comments
 (0)