mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
Replace the systemd unit files that needed to be modified for a specific interface with template files. The template files allows one to instansiate a service for any interface (by running systemctl start pping@<interface>.service), and multiple interfaces can be monitored at once. Each instance maintains a separtate "log" of data at /sys/var/log/pping/<interface>/pping.<interface>.json which is rotated one per minute (see the rotate-pping@.timer file) and placed in daily subfolders. Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
44 lines
951 B
Bash
Executable File
44 lines
951 B
Bash
Executable File
#!/bin/bash
|
|
|
|
MAX_WAIT_ITER=10
|
|
pping_path=${1:-"/var/log/pping/pping.out.json"}
|
|
instance=$2 # pping service instance to reload
|
|
|
|
pping_folder=$(dirname "$pping_path")
|
|
pping_file=$(basename "$pping_path")
|
|
|
|
if [[ ! -f "$pping_path" ]]; then
|
|
# Nothing to rotate
|
|
exit 0
|
|
fi
|
|
|
|
dailyfolder="$pping_folder/$(date -Idate)"
|
|
if ! mkdir -p "$dailyfolder"; then
|
|
exit 1
|
|
fi
|
|
|
|
newplace="$dailyfolder/$pping_file.$(date -Iseconds)"
|
|
if ! mv "$pping_path" "$newplace"; then
|
|
exit 1
|
|
fi
|
|
|
|
|
|
if [[ -n "$instance" ]] && systemctl is-active --quiet "pping@$instance.service"; then
|
|
systemctl reload "pping@$instance.service"
|
|
fi
|
|
|
|
# Compress the old file (once ePPing has stopped writing to it)
|
|
if [[ -f "$newplace" ]]; then
|
|
for (( i = 0; i < MAX_WAIT_ITER; i++)); do
|
|
if fuser -s "$newplace"; then
|
|
sleep 1
|
|
else
|
|
gzip "$newplace"
|
|
exit $?
|
|
fi
|
|
done
|
|
fi
|
|
|
|
echo "Timed out waiting for $newplace to become unused, unable to compress it" 1>&2
|
|
exit 1
|