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>
This commit is contained in:
Simon Sundberg
2023-07-05 19:39:24 +02:00
parent 9ba9e7cd08
commit 6582f6713c
4 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,41 @@
#!/bin/bash
MAX_WAIT_ITER=10
pping_path=${1:-"/var/log/pping/pping.out.json"}
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
# Tell ePPing to reopen file
if systemctl is-active --quiet pping.service; then
systemctl reload pping.service
fi
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