server-scripts/docker-updater.sh

55 lines
1.2 KiB
Bash
Raw Normal View History

#!/bin/bash
### AUTO-UPDATER ###
FILE_NAME="docker-updater.sh"
SERVER_FILE="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main/$FILE_NAME"
2024-12-28 21:18:35 -03:00
SERVER_AU="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main/auto-updater.sh"
2024-12-28 21:18:35 -03:00
# Run auto-updater script
curl -sSL $SERVER_AU | bash
####################
# Navigate to docker folder
DOCKER_FOLDER=/root/docker
if [ -d "$DOCKER_FOLDER" ]; then
cd $DOCKER_FOLDER
else
echo "Error: $DOCKER_FOLDER not found." >&2
exit 1
fi
# Navigate on each folder and run docker-compose stop, pull and up -d
for folder in */; do
cd $folder
2024-12-28 21:13:05 -03:00
2024-12-28 21:13:51 -03:00
DOCKER_RUNNING=$(docker-compose ps -q)
2024-12-28 21:13:05 -03:00
if [ -n "$DOCKER_RUNNING" ]; then
echo "[$folder] Stopping Docker containers"
2024-12-28 21:18:35 -03:00
docker-compose down > /dev/null
2024-12-28 21:13:05 -03:00
else
echo "[$folder] No Docker containers running"
fi
echo "[$folder] Updating images"
2024-12-28 21:18:35 -03:00
docker-compose pull > /dev/null
2024-12-28 21:13:05 -03:00
if [ -n "$DOCKER_RUNNING" ]; then
echo "[$folder] Starting Docker containers"
2024-12-28 21:18:35 -03:00
docker-compose up -d > /dev/null
2024-12-28 21:13:05 -03:00
fi
echo "[$folder] Updated!"
cd ..
done
# Run Docker image prune
echo "Running Docker image prune..."
docker image prune -af
2024-12-28 21:13:05 -03:00
echo "Done!"