woodpecker/fix_database.sh

77 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# Script to fix database issues for Woodpecker
echo "===== CHECKING DATABASE SERVICE ====="
docker service ls | grep woodpecker_db || {
echo "ERROR: woodpecker_db service not found"
echo "Please deploy the stack first"
exit 1
}
echo "===== DATABASE SERVICE DETAILS ====="
docker service ps woodpecker_db --no-trunc
echo "===== DATABASE LOGS ====="
docker service logs --tail 30 woodpecker_db
echo "===== CHECKING DATABASE DIRECTORY ON MACMINI1 ====="
echo "Note: This requires SSH access to macmini1 or shared storage"
ls -la /mnt/data/nixc.us/woodpecker/production/db || {
echo "WARNING: Could not access database directory locally"
echo "Attempting to check via SSH..."
ssh macmini1 "ls -la /mnt/data/nixc.us/woodpecker/production/db" || {
echo "ERROR: Could not check database directory on macmini1 via SSH"
}
}
echo "===== FIXING DATABASE PERMISSIONS ====="
echo "Setting permissions on database directory..."
chmod -R 777 /mnt/data/nixc.us/woodpecker/production/db || {
echo "WARNING: Could not set permissions locally"
echo "Attempting to set permissions via SSH..."
ssh macmini1 "chmod -R 777 /mnt/data/nixc.us/woodpecker/production/db" || {
echo "ERROR: Could not set permissions on macmini1 via SSH"
}
}
echo "===== CHECKING FOR CORRUPTED DATABASE FILES ====="
echo "Looking for InnoDB files that might be causing issues..."
find /mnt/data/nixc.us/woodpecker/production/db -name "ib_logfile*" || {
echo "No InnoDB log files found locally"
echo "Attempting to check via SSH..."
ssh macmini1 "find /mnt/data/nixc.us/woodpecker/production/db -name \"ib_logfile*\"" || {
echo "ERROR: Could not check for InnoDB files on macmini1 via SSH"
}
}
echo "===== REMOVING CORRUPTED DATABASE FILES (IF ANY) ====="
echo "This will only remove InnoDB log files that might be causing corruption"
echo "Your actual database data will not be affected"
echo "Removing InnoDB log files..."
rm -f /mnt/data/nixc.us/woodpecker/production/db/ib_logfile* || {
echo "WARNING: Could not remove files locally"
echo "Attempting to remove via SSH..."
ssh macmini1 "rm -f /mnt/data/nixc.us/woodpecker/production/db/ib_logfile*" || {
echo "ERROR: Could not remove files on macmini1 via SSH"
}
}
echo "===== RESTARTING DATABASE SERVICE ====="
docker service update --force woodpecker_db
echo "===== WAITING FOR DATABASE TO RESTART ====="
echo "Waiting 30 seconds for database to restart..."
sleep 30
echo "===== CHECKING DATABASE STATUS ====="
docker service ps woodpecker_db --no-trunc
echo "===== CHECKING DATABASE LOGS AFTER RESTART ====="
docker service logs --tail 20 woodpecker_db
echo "===== DONE ====="
echo "If the database is still not running, you may need to try the following:"
echo "1. Remove all files from /mnt/data/nixc.us/woodpecker/production/db"
echo "2. Redeploy the stack"
echo "This will reset your database, but will fix persistent corruption issues."