2024-02-15 09:30:08 -05:00
|
|
|
#!/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..."
|
2024-02-15 19:43:33 -05:00
|
|
|
# Stop Jellyfin
|
|
|
|
sudo systemctl stop jellyfin
|
|
|
|
# Remove bad DB
|
2024-02-15 09:30:08 -05:00
|
|
|
rm -f /var/lib/jellyfin/data/library.db
|
2024-02-15 19:43:33 -05:00
|
|
|
# Replace bad DB
|
2024-02-15 11:10:14 -05:00
|
|
|
cp "/path/to/backups/Jellyfin/library.db" "/var/lib/jellyfin/data/library.db"
|
2024-02-15 19:43:33 -05:00
|
|
|
# Fix Permissions
|
2024-02-15 11:10:14 -05:00
|
|
|
/usr/bin/chown jellyfin:jellyfin "/var/lib/jellyfin/data/library.db"
|
|
|
|
echo "Database file replaced with backup."
|
2024-02-15 09:30:08 -05:00
|
|
|
|
2024-02-15 19:43:33 -05:00
|
|
|
# Start Jellyfin
|
|
|
|
sudo systemctl start jellyfin
|
|
|
|
sleep 30
|
|
|
|
|
2024-02-15 09:30:08 -05:00
|
|
|
# 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
|
2024-09-17 14:44:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
#Even if no DB curruption, update the live TV, why not?
|
|
|
|
# Trigger Live TV / M3U scan
|
|
|
|
echo "Triggering Live TV / M3U scan..."
|
|
|
|
curl -X POST \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-H "X-Emby-Token: $API_KEY" \
|
|
|
|
"$JELLYFIN_URL/ScheduledTasks/Running/bea9b218c97bbf98c5dc1303bdb9a0ca"
|
|
|
|
echo "Live TV / M3U scan triggered."
|
|
|
|
|
2024-02-15 11:10:14 -05:00
|
|
|
exit 0
|