Add Jellyfin_Fix_and_Scan.sh

I got tired of messing with corrupt library.db files and Jellyfin not starting.
This automates "fixing" the issue.
This commit is contained in:
Clarth 2024-02-15 09:30:08 -05:00
commit 27fdb084f9
1 changed files with 34 additions and 0 deletions

34
Jellyfin_Fix_and_Scan.sh Normal file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# Define your Jellyfin server URL and API key
JELLYFIN_URL="http://127.0.0.1:8096"
API_KEY="API KEY"
# Run journalctl command and search for the specified error messages
error_message_1="database disk image is malformed"
error_message_2="database or disk is full"
error_found_1=$(journalctl -u jellyfin --since "1 hour ago" | grep "$error_message_1")
error_found_2=$(journalctl -u jellyfin --since "1 hour ago" | grep "$error_message_2")
# If either error message is found, delete the database file and trigger library scan
if [ -n "$error_found_1" ] || [ -n "$error_found_2" ]; then
echo "Error found in journal, deleting database file..."
rm -f /var/lib/jellyfin/data/library.db
echo "Database file deleted."
# Trigger library scan
echo "Triggering library scan..."
curl -X POST \
-H "Content-Type: application/json" \
-H "X-Emby-Token: $API_KEY" \
-d '{"Recursive":true}' \
"$JELLYFIN_URL/library/refresh"
echo "Library scan triggered."
# Send Telegram message to admin
curl -s -X POST -d "chat_id=CHAT ID" -d text="Jellyfin library.db had issues today. Check the logs!" https://api.telegram.org/botBOT:TOKEN/sendMessage
else
echo "No error found in journal."
fi
exit 0