Created
September 23, 2023 20:03
-
-
Save Deathproof76/af1ec37bd377a36adbbea5cc5f8486b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -x # Enable debug mode | |
# Function to check the health of the plex container | |
check_plex_health() { | |
# Directly print the logs to the terminal for debugging | |
docker logs --tail 10 plex | |
# Get the last 10 lines of log output from the container named plex | |
plex_logs=$(docker logs --tail 10 plex) | |
echo "Plex logs: $plex_logs" # Print the logs for debugging | |
# Count the number of times the "Sqlite3: Sleeping for 200ms to retry busy DB" line appears in the logs | |
count=$(grep -c "Sqlite3: Sleeping for 200ms to retry busy DB" <<< "$plex_logs") | |
echo "Count of 'Sqlite3' lines: $count" # Print the count for debugging | |
# If the line appears more than 3 times, return a non-zero exit code to indicate a failure | |
if [ "$count" -gt 3 ]; then | |
echo "Oh no, I guess we have to restart the container." | |
return 1 | |
fi | |
# Otherwise, return a success exit code and print a message to the terminal | |
echo "Plex seems to be okay! I just checked!" | |
return 0 | |
} | |
# Run the health check function continuously | |
while true; do | |
check_plex_health | |
# If the health check fails, restart the plex container | |
if [ $? -ne 0 ]; then | |
echo "Restarting Plex container..." # Debug statement | |
docker restart plex | |
fi | |
# Sleep for 3 minutes between each health check | |
sleep 180 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment