Upstream patches and additional patching (#2)

* Ensures DSM GUI refreshes its updates

* Removed whale icon and changed verbosity

* Added addon for Prometheus+node_exporter

* Changed local image check to check on image ID rather than name

* Update podcheck.sh

changed docker->podman, typo

* - **v0.6.0**:
    - **Grafana & Prometheus Integration:**
      - Added a detailed Prometheus metrics exporter that now reports not only the number of containers with updates, no-updates, and errors, but also the total number of containers checked, the duration of the update check, and the epoch timestamp of the last check.
      - Enhanced documentation with instructions on integrating these metrics with Grafana for visual monitoring.
    - **Improved Error Handling & Code Refactoring:**
      - Introduced `set -euo pipefail` and local variable scoping within functions to improve reliability and prevent unexpected behaviour.
      - Standardised container name handling and refined the Quadlet detection logic.
    - **Self-Update Enhancements:**
      - Updated the self-update mechanism to support both Git-based and HTTP-based updates, with an automatic restart that preserves the original arguments.
    - **Miscellaneous Improvements:**
      - Enhanced dependency installer to support both package manager and static binary installations for `jq` and `regctl`.
      - General code refactoring across the project for better readability and maintainability.

* Update podcheck.sh

* increment version

* Update Quadlet detection logic 

Update Quadlet detection logic to support flexible service naming

- Modified the quadlet update block to first try an exact match for "$i.service".
- If no exact match is found, build a regex pattern from the container name (allowing underscores and hyphens interchangeably) and search user service units.
- When multiple candidate units are found, the script attempts to choose the one that exactly matches (ignoring case) or defaults to the first candidate.
- This update allows containers like "containera" to match service units named "container_a.service" and supports scenarios with multiple counterparts (e.g., matrix-a, matrix-b, matrix_db).

* search name fix

* fixes to arg parsing

* Logic overhaul, verbose output and better syntax

* Added support for prometheus

---------

Co-authored-by: mag37 <robin.ivehult@gmail.com>
This commit is contained in:
Joe Harrison 2025-02-25 14:12:01 +00:00 committed by GitHub
parent 053c587bf5
commit a7dcd975b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 953 additions and 245 deletions

View file

@ -1,9 +1,9 @@
# A small guide on getting started with Apprise notifications.
## Standalone docker container: [linuxserver/apprise-api](https://hub.docker.com/r/linuxserver/apprise-api)
## Standalone podman container: [linuxserver/apprise-api](https://hub.docker.com/r/linuxserver/apprise-api)
Set up the docker compose as preferred:
Set up the podman compose as preferred:
```yaml
---
version: "2.1"

View file

@ -1,51 +0,0 @@
#!/usr/bin/env bash
### If not in PATH, set full path. Else just "regctl"
regbin="regctl"
### options to allow exclude:
while getopts "e:" options; do
case "${options}" in
e) Exclude=${OPTARG} ;;
*) exit 0 ;;
esac
done
shift "$((OPTIND-1))"
### Create array of excludes
IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
SearchName="$1"
for i in $(podman ps --filter "name=$SearchName" --format '{{.Names}}') ; do
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
printf ". "
RepoUrl=$(podman inspect "$i" --format='{{.ImageName}}')
LocalHash=$(podman image inspect "$RepoUrl" --format '{{.Digest}}')
### Checking for errors while setting the variable:
if RegHash=$($regbin image digest --list "$RepoUrl" 2>/dev/null) ; then
if [[ "$LocalHash" == "$RegHash" ]] ; then NoUpdates+=("$i"); else GotUpdates+=("$i"); fi
else
GotErrors+=("$i")
fi
done
### Sort arrays alphabetically
IFS=$'\n'
NoUpdates=($(sort <<<"${NoUpdates[*]}"))
GotUpdates=($(sort <<<"${GotUpdates[*]}"))
GotErrors=($(sort <<<"${GotErrors[*]}"))
unset IFS
### List what containers got updates or not
if [[ -n ${NoUpdates[*]} ]] ; then
printf "\n\033[0;32mContainers on latest version:\033[0m\n"
printf "%s\n" "${NoUpdates[@]}"
fi
if [[ -n ${GotErrors[*]} ]] ; then
printf "\n\033[0;31mContainers with errors; won't get updated:\033[0m\n"
printf "%s\n" "${GotErrors[@]}"
fi
if [[ -n ${GotUpdates[*]} ]] ; then
printf "\n\033[0;33mContainers with updates available:\033[0m\n"
printf "%s\n" "${GotUpdates[@]}"
fi
printf "\n\n"

View file

@ -1,37 +1,55 @@
#!/usr/bin/env bash
# Usage: ./script.sh <SearchName>
SearchName="$1"
for i in $(podman ps --filter "name=$SearchName" --format '{{.Names}}') ; do
echo "------------ $i ------------"
ContLabels=$(podman inspect "$i" --format '{{json .Config.Labels}}')
ContImage=$(podman inspect "$i" --format='{{.ImageName}}')
# Iterate over containers whose name contains the search term.
podman ps --filter "name=$SearchName" --format '{{.Names}}' | while read -r container; do
echo "------------ $container ------------"
# Retrieve container labels and image name.
ContLabels=$(podman inspect "$container" --format '{{json .Config.Labels}}')
ContImage=$(podman inspect "$container" --format '{{.ImageName}}')
# Extract values from labels; if not set, default to an empty string.
ContPath=$(jq -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
[ "$ContPath" == "null" ] && ContPath=""
ContConfigFile=$(jq -r '."com.docker.compose.project.config_files"' <<< "$ContLabels")
[ "$ContConfigFile" == "null" ] && ContConfigFile=""
ContName=$(jq -r '."com.docker.compose.service"' <<< "$ContLabels")
[ "$ContName" == "null" ] && ContName=""
ContEnv=$(jq -r '."com.docker.compose.project.environment_file"' <<< "$ContLabels")
[ "$ContEnv" == "null" ] && ContEnv=""
ContUpdateLabel=$(jq -r '."sudo-kraken.podcheck.update"' <<< "$ContLabels")
[ "$ContUpdateLabel" == "null" ] && ContUpdateLabel=""
ContRestartStack=$(jq -r '."sudo-kraken.podcheck.restart-stack"' <<< "$ContLabels")
[ "$ContRestartStack" == "null" ] && ContRestartStack=""
if [[ $ContConfigFile = '/'* ]] ; then
# Determine the compose file location.
if [[ $ContConfigFile = '/'* ]]; then
ComposeFile="$ContConfigFile"
else
ComposeFile="$ContPath/$ContConfigFile"
fi
# Output the extracted details.
echo -e "Service name:\t\t$ContName"
echo -e "Project working dir:\t$ContPath"
echo -e "Compose files:\t\t$ComposeFile"
echo -e "Environment files:\t$ContEnv"
echo -e "Container image:\t$ContImage"
echo -e "Update label:\t$ContUpdateLabel"
echo -e "Update label:\t\t$ContUpdateLabel"
echo -e "Restart Stack label:\t$ContRestartStack"
echo
echo "Mounts:"
podman inspect -f '{{ range .Mounts }}{{ .Source }}:{{ .Destination }}{{ printf "\n" }}{{ end }}' "$i"
# Display container mount points.
podman inspect -f '{{ range .Mounts }}{{ .Source }}:{{ .Destination }}{{ "\n" }}{{ end }}' "$container"
echo
done

61
extras/pc_brief.sh Normal file
View file

@ -0,0 +1,61 @@
#!/usr/bin/env bash
# pc_brief.sh - Provides a brief diagnostic summary of Podman Compose containers.
# Usage: pc_brief.sh <name-filter>
set -euo pipefail
# Check if a name filter argument was provided
if [ "$#" -eq 0 ]; then
echo "Usage: $0 <name-filter>"
exit 1
fi
SearchName="$1"
# Use a while-read loop to correctly handle container names with spaces
podman ps --filter "name=$SearchName" --format '{{.Names}}' | while IFS= read -r container; do
echo "------------ $container ------------"
# Retrieve container labels and image name
ContLabels=$(podman inspect "$container" --format '{{json .Config.Labels}}')
ContImage=$(podman inspect "$container" --format '{{.ImageName}}')
# Extract Docker Compose-related labels via jq; default to empty if null
ContPath=$(jq -r '."com.docker.compose.project.working_dir"' <<< "$ContLabels")
[ "$ContPath" == "null" ] && ContPath=""
ContConfigFile=$(jq -r '."com.docker.compose.project.config_files"' <<< "$ContLabels")
[ "$ContConfigFile" == "null" ] && ContConfigFile=""
ContName=$(jq -r '."com.docker.compose.service"' <<< "$ContLabels")
[ "$ContName" == "null" ] && ContName=""
ContEnv=$(jq -r '."com.docker.compose.project.environment_file"' <<< "$ContLabels")
[ "$ContEnv" == "null" ] && ContEnv=""
ContUpdateLabel=$(jq -r '."sudo-kraken.podcheck.update"' <<< "$ContLabels")
[ "$ContUpdateLabel" == "null" ] && ContUpdateLabel=""
ContRestartStack=$(jq -r '."sudo-kraken.podcheck.restart-stack"' <<< "$ContLabels")
[ "$ContRestartStack" == "null" ] && ContRestartStack=""
# Determine the full path to the compose file(s)
if [[ $ContConfigFile = /* ]]; then
ComposeFile="$ContConfigFile"
else
ComposeFile="$ContPath/$ContConfigFile"
fi
# Output a concise summary of container configuration
echo -e "Service name:\t\t$ContName"
echo -e "Project working dir:\t$ContPath"
echo -e "Compose files:\t\t$ComposeFile"
echo -e "Environment files:\t$ContEnv"
echo -e "Container image:\t$ContImage"
echo -e "Update label:\t\t$ContUpdateLabel"
echo -e "Restart Stack label:\t$ContRestartStack"
echo
echo "Mounts:"
podman inspect -f '{{ range .Mounts }}{{ .Source }}:{{ .Destination }}{{ "\n" }}{{ end }}' "$container"
echo
done