forked from pinks/eris
1
0
Fork 0
nyx/monitoring/sleepy.sh

31 lines
968 B
Bash

#!/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