From 72272cacacc6bf3788076199d8902639f4b49eb0 Mon Sep 17 00:00:00 2001 From: Jose Henrique Date: Sat, 28 Dec 2024 21:13:05 -0300 Subject: [PATCH] improving --- README.md | 6 +++++- docker-updater.sh | 25 +++++++++++++++++++------ scripts-download.sh | 12 +++++++++++- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7cbad27..499959f 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,8 @@ This script is used to backup a directory to a remote server using `rsync`. It i ### `clean.sh` -This script is used to clean some of the files, docker dangling images, and docker stopped/unused containers. \ No newline at end of file +This script is used to clean some of the files, docker dangling images, and docker stopped/unused containers. + +### `docker-updater.sh` + +This script is used to update all the docker containers on the server. \ No newline at end of file diff --git a/docker-updater.sh b/docker-updater.sh index 7633d41..9f9e0d7 100644 --- a/docker-updater.sh +++ b/docker-updater.sh @@ -53,12 +53,25 @@ fi for folder in */; do cd $folder - echo "Updating $folder..." - docker-compose down - docker-compose pull - docker-compose up -d - echo "Updated $folder!" + DOCKER_RUNNING = $(docker-compose ps -q) + + if [ -n "$DOCKER_RUNNING" ]; then + echo "[$folder] Stopping Docker containers" + docker-compose down + else + echo "[$folder] No Docker containers running" + fi + + echo "[$folder] Updating images" + docker-compose pull + + if [ -n "$DOCKER_RUNNING" ]; then + echo "[$folder] Starting Docker containers" + docker-compose up -d + fi + + echo "[$folder] Updated!" cd .. done @@ -68,4 +81,4 @@ done echo "Running Docker image prune..." docker image prune -af -echo "Done." \ No newline at end of file +echo "Done!" \ No newline at end of file diff --git a/scripts-download.sh b/scripts-download.sh index c02aff8..2ebb494 100644 --- a/scripts-download.sh +++ b/scripts-download.sh @@ -149,7 +149,17 @@ for FILE in "${FILES[@]}"; do echo -e "${LIGHT_BLUE}[i] [$FILE] Crontab already exists. Skipping.${NC}" else echo -e "${LIGHT_BLUE}[i] [$FILE] Adding crontab...${NC}" - (crontab -l 2>/dev/null; echo "0 0 * * * ${CURRENT_WORKDIR}/$FILE") | crontab - + + if [ "$FILE" == "clean.sh" ]; then + (crontab -l 2>/dev/null; echo "0 0 * * * ${CURRENT_WORKDIR}/$FILE") | crontab - + elif [ "$FILE" == "backup.sh" ]; then + (crontab -l 2>/dev/null; echo "0 0 * * * ${CURRENT_WORKDIR}/$FILE") | crontab - + elif [ "$FILE" == "docker-updater.sh" ]; then + (crontab -l 2>/dev/null; echo "0 3 */4 * * ${CURRENT_WORKDIR}/$FILE") | crontab - + else + echo -e "${YELLOW}[w] [$FILE] Warning: Crontab specific schedule not setup.${NC}" >&2 + (crontab -l 2>/dev/null; echo "0 0 * * * ${CURRENT_WORKDIR}/$FILE") | crontab - + fi echo -e "${GREEN}[✓] [$FILE] Crontab added, double-checking set up...${NC}"