From 6b1790171d8b4fc059442b9676f1e860168e4fd2 Mon Sep 17 00:00:00 2001 From: Matan Horovitz Date: Fri, 17 Nov 2023 16:50:20 +0200 Subject: [PATCH] Hatarashi Hako now provides Prometheus metrics; old updates --- HatarashiHako | 45 ++++++++++++--------------------------------- Kumonoboru | 19 ++++++++++--------- Murchison | 7 +++---- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/HatarashiHako b/HatarashiHako index e8d5b50..f5844fc 100755 --- a/HatarashiHako +++ b/HatarashiHako @@ -21,7 +21,7 @@ flag_error() help() { - echo "$arg0 - show how long a process has been running" + echo "$arg0 - Smartly update container stack" echo " {-s|--stack} [name] -- Run update process just for specified stack (ex: vikunja)" echo " {-v|--verbose|verbose} -- Print debug messages" echo " {-h|--help} -- Print this help message and exit" @@ -69,9 +69,11 @@ declare -a CONTAINER_PATHS declare -a OUTDATED_CONTAINERS declare -a FAILED_CONTAINERS declare -a UPDATED_CONTAINERS + +PROM_FILE="/var/Red-Vol/Media/Containers/prometheus/data/hatarashi-hako.prom" #Remove log from last runs, if present -if [[ -f /tmp/docker-updated ]]; then - rm /tmp/docker-updated +if [[ -f $PROM_FILE ]]; then + rm $PROM_FILE fi #Start counting how many containers fail; appears in final mail subject. OUTDATED_COUNT="0" @@ -112,7 +114,7 @@ for container_path in ${CONTAINER_PATHS[@]}; do if [[ -z $local_image ]]; then error "Error fetching local image checksum for container $container_name!" #The script will complain about failed containers later on - FAILED_CONTAINERS+=("(local) $container_name") + echo "container_updated{name=\"$container_name\"} -1" >> $PROM_FILE continue 2 else debug "Local SHA256 for $container_image is" "$local_image" @@ -127,7 +129,7 @@ for container_path in ${CONTAINER_PATHS[@]}; do #Now, if you still don't have an image after the second try, something's fuckey. if [[ -z $remote_image ]]; then error "Error fetching remote image checksum for container" "$container_name!" - FAILED_CONTAINERS+=("(remote) $container_name") + echo "container_updated{name=\"$container_name\"} -1" >> $PROM_FILE continue 2 else debug "Remote SHA256 for $container_image is" "$remote_image" @@ -141,24 +143,18 @@ for container_path in ${CONTAINER_PATHS[@]}; do service=$(cat "$container_path/docker-compose.yml" | grep -B1 "image: $container_image" | head -1 | sed -e 's/^[ \t]*//' -e 's/://g' | grep -v 'container_name') # get container service name (1 line above image) ^ print service name^ ^ omit tabs and : and ^omit container_name info "Attempting to update service" "$service" - if docker-compose pull $service; then + if docker compose pull $service; then info "Pulled latest image for" "$container_name" - if docker-compose up -d --remove-orphans; then + if docker compose up -d --remove-orphans; then ok "$container_stack" "has been updated sucessfully!" - UPDATED_CONTAINERS+=("($container_stack) $container_name") + echo "container_updated{name=\"$container_name\"} 1" >> $PROM_FILE else error "Failed to update" "$container_name!" - FAILED_CONTAINERS+=("($container_stack|update) $container_name") - #Add to array for mail report - OUTDATED_CONTAINERS+=("($container_stack) $container_name") - export OUTDATED_COUNT=$(($OUTDATED_COUNT+1)) + echo "container_updated{name=\"$container_name\"} 0" >> $PROM_FILE fi else error "Failed to pull image for" "$container_name!" - FAILED_CONTAINERS+=("($container_stack|pull) $container_name") - #Add to array for mail report - OUTDATED_CONTAINERS+=("($container_stack) $container_name") - export OUTDATED_COUNT=$(($OUTDATED_COUNT+1)) + echo "container_updated{name=\"$container_name\"} 0" >> $PROM_FILE fi fi #If you found an image tag, reset it before moving on to another container @@ -167,20 +163,3 @@ for container_path in ${CONTAINER_PATHS[@]}; do cd $LOCAL_DIR done echo "All done!" -#Iterate over the arrays and output results to a file; if needed, it will be neatly mailed. -if [[ ${#OUTDATED_CONTAINERS[@]} != 0 ]] || [[ ${#FAILED_CONTAINERS[@]} != 0 ]] || [[ ${#UPDATED_CONTAINERS[@]} != 0 ]]; then - if [[ ${#UPDATED_CONTAINERS[@]} != 0 ]]; then - printf "The following containers have updated succefully:\n" > /tmp/docker-updated - printf "%s\n" "${UPDATED_CONTAINERS[@]}" >> /tmp/docker-updated - fi - if [[ ${#OUTDATED_CONTAINERS[@]} != 0 ]]; then - printf "The following containers are out of date:\n" >> /tmp/docker-updated - printf "%s\n" "${OUTDATED_CONTAINERS[@]}" >> /tmp/docker-updated - fi - if [[ ${#FAILED_CONTAINERS[@]} != 0 ]]; then - printf "The following containers failed the update process:\n" >> /tmp/docker-updated - printf "%s\n" "${FAILED_CONTAINERS[@]}" >> /tmp/docker-updated - fi - cat /tmp/docker-updated | mail -s "Docker containers update report - `date +"%B %d %Y"`" -r "Takahe@pukeko.xyz" matanhorovitz@protonmail.com - rm /tmp/docker-updated -fi diff --git a/Kumonoboru b/Kumonoboru index bf96c74..8523c20 100755 --- a/Kumonoboru +++ b/Kumonoboru @@ -141,8 +141,17 @@ clean(){ fi fi } + +#If cleaning was forced, or if it's the first of this month - clean. +if [[ -n $CLEAN ]] || [[ $(date +%d) == "1" ]]; then + check Gerbil-TK + clean Gerbil-TK + check Pukeko-XYZ-Containers + clean Pukeko-XYZ-Containers + check Pukeko-XYZ-Cloud + clean Pukeko-XYZ-Cloud #If a specific repository was requested, back it up; otherwise, back them all up. -if [[ -n $REPOSITORY ]] && [[ -z $CLEAN ]]; then +elif [[ -n $REPOSITORY ]] && [[ -z $CLEAN ]]; then case "$REPOSITORY" in (Gerbil-TK) backup Gerbil-TK /var/Red-Vol/Media/Pictures/ @@ -179,14 +188,6 @@ elif [[ -n $REPOSITORY ]] && [[ -n $CLEAN ]]; then (*) help;; esac -#If cleaning was forced, or if it's the first of this month - clean. -elif [[ -n $CLEAN ]] || [[ $(date +%d) == "1" ]]; then - check Gerbil-TK - clean Gerbil-TK - check Pukeko-XYZ-Containers - clean Pukeko-XYZ-Containers - check Pukeko-XYZ-Cloud - clean Pukeko-XYZ-Cloud fi #Wrap up this run's log and report nicely echo "All done; have a nice day!" diff --git a/Murchison b/Murchison index 09b9a3e..f83c6d9 100755 --- a/Murchison +++ b/Murchison @@ -1,7 +1,6 @@ #!/bin/bash #Script to backup all important environment files -source /etc/environment -source $SCRIPTS/Okiru +source /home/shmick/Scripts/Okiru logging "ConfigBackup" export CONF_DIR="/home/shmick/Config" if [[ ! -d $CONF_DIR ]]; then @@ -48,10 +47,10 @@ conf_sync /etc/profile for conf in $(ls /etc/snapper/configs/* 2> /dev/null); do conf_sync $conf done -for conf in $(ls /etc/systemd/system/murchison*); do +for conf in $(ls /etc/systemd/system/Murchison*); do conf_sync $conf done -for conf in $(ls /etc/systemd/system/kumonoboru*); do +for conf in $(ls /etc/systemd/system/Kumonoboru*); do conf_sync $conf done #Fix permissions