From 520e0d4924c34992d6f4300bfc1f1b2558940d1d Mon Sep 17 00:00:00 2001 From: "Bastian (BaM)" Date: Sat, 13 Sep 2025 17:00:05 +0200 Subject: [PATCH] Allow only one instance to run --- auto-boot-ollama-pc.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/auto-boot-ollama-pc.sh b/auto-boot-ollama-pc.sh index 06b96a1..3e203b6 100755 --- a/auto-boot-ollama-pc.sh +++ b/auto-boot-ollama-pc.sh @@ -1,5 +1,6 @@ #!/bin/bash set -euo pipefail +SCRIPTNAME=$(basename "$(readlink -f "$0")") # ========= Configuration ========= CONTAINER_NAME="paperless-ai" @@ -7,11 +8,18 @@ OLLAMA_HOST="192.168.222.12" OLLAMA_PORT="11434" ERROR_PATTERN="Error: \[ERROR\] Document analysis failed: connect EHOSTUNREACH $OLLAMA_HOST:$OLLAMA_PORT" + # Tools (adjust if your distro uses different names) WOL_CMD="wakeonlan" # or "etherwake -i eth0 $WOL_MAC" NC_CMD="nc" # netcat DOCKER="docker" +# Ensure only one instance of this script is running +if pgrep -f $SCRIPTNAME 1>/dev/null; then + echo "Killing running instance of $SCRIPTNAME..." + pgrep -f -- "$SCRIPTNAME" | grep -vw "$$" | xargs -r kill -KILL +fi + log() { printf '[%(%F %T)T] %s\n' -1 "$*"; } ${DOCKER} logs -f --since 0s "${CONTAINER_NAME}" 2>&1 | \