From aefbc63a4671f97bca30524661b5215b16e87172 Mon Sep 17 00:00:00 2001 From: Akiru Date: Thu, 25 Jan 2024 08:38:14 +0000 Subject: [PATCH] =?UTF-8?q?monitoring/sleepy.sh=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitoring/sleepy.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 monitoring/sleepy.sh diff --git a/monitoring/sleepy.sh b/monitoring/sleepy.sh new file mode 100644 index 0000000..2bf0128 --- /dev/null +++ b/monitoring/sleepy.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# When the bot gets eepy sleepy, this script will restart it. It happens, when no jobs come in for multiple minutes. +# The script interfaces with the REST API of the bot and checks if the image count has changed. +# Run this script as cronjob all 4-5 minutes. + +# Define the URL and the stats file path +URL="https://YOUR_URL/api/stats" +STATS_FILE="YOUR_FILE_PATH/stats.txt" + +# Fetch the data and extract imageCount +imageCount=$(curl -s "$URL" | jq '.imageCount') + +# Check if stats file exists and read the last value +if [ -f "$STATS_FILE" ]; then + lastValue=$(tail -n 1 "$STATS_FILE") +else + lastValue="" +fi + +# Save the new value to the file +echo "$imageCount" >> "$STATS_FILE" + +# Keep only the last 2 values in the file +tail -n 2 "$STATS_FILE" > "$STATS_FILE.tmp" && mv "$STATS_FILE.tmp" "$STATS_FILE" + +# Compare the two values and restart the service if they are the same +if [ "$lastValue" == "$imageCount" ]; then + systemctl restart nyxthebot +fi