Housekeeping and script hardening in /srv/docker/bridgehead. Existing installations need to run bridgehead uninstall, bridgehead install.

This commit is contained in:
Martin Lablans
2022-05-09 15:13:38 +02:00
parent 445add6d30
commit 334f82661b
13 changed files with 123 additions and 101 deletions

34
lib/update-bridgehead.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
service="bridgehead"
source lib/functions.sh
#checkRequirements // not required for mere update
log "INFO" "Checking for updates of $service"
# check prerequisites
# check if updates are available
old_git_hash="$(git rev-parse --verify HEAD)"
git fetch 2>&1
git pull 2>&1
new_git_hash="$(git rev-parse --verify HEAD)"
git_updated="false"
if [ "$old_git_hash" != "$new_git_hash" ]; then
log "INFO" "Pulled new changes from origin"
git_updated="true"
fi
docker_updated="false"
for image in $(docker ps --filter "name=$service" --format {{.Image}}); do
log "INFO" "Checking for Updates of Image: $image"
if docker pull $image | grep "Downloaded newer image"; then
log "INFO" "$image updated."
docker_updated="true"
fi
done
if [ $git_updated = "true" ] || [ $docker_updated = "true" ]; then
log "INFO" "Due to previous updates now restarting $service@$1"
systemctl restart "$service@$1.service"
fi
log "INFO" "checking updates finished"
exit 0