netz39-infra-ansible/templates/hobbes/kiosk.sh.j2
Stefan Haun 592d864283 Fix Grafana Kiosk to use killall
Fbi seems to fork and continue on another process, as the shown process ID does not
match the returned value. Use killall to fix this problem.

Note that this only works because nobody else is using fbi on the system.
2024-01-07 20:29:06 +01:00

44 lines
1 KiB
Django/Jinja

#!/bin/bash
# Check if the script is run by root
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# MQTT broker details
BROKER="{{ kiosk_mqtt_host }}"
TOPIC="{{ kiosk_mqtt_topic }}"
# Variable to store the PID of the fbi process
fbi_pid=0
# Function to be executed on SIGTERM
on_sigterm() {
echo "SIGTERM received, exiting..."
# Kill the fbi process
# As the process forks itself, we do not get a reliable PID and killall is needed
killall fbi
# Remove the temporary file
rm -f /tmp/grafana.png
exit 0
}
# Trap SIGTERM and call on_sigterm() when it is received
trap 'on_sigterm' SIGTERM
while true
do
# Subscribe to the topic and save received data to a file
mosquitto_sub -h $BROKER -t $TOPIC -C 1 > /tmp/grafana.png
# Kill the previous fbi process
# As the process forks itself, we do not get a reliable PID and killall is needed
killall fbi
# Wait to avoid a race condition between
# fbi starting and mosquitto truncating the file
sleep 1
done