pping: Change single pping-service into generic template

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>
This commit is contained in:
Simon Sundberg
2023-07-08 17:45:30 +02:00
parent c6751effb0
commit f423e39d6b
6 changed files with 53 additions and 52 deletions

View File

@@ -2,6 +2,7 @@
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")
@@ -21,11 +22,12 @@ 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
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