Refactor Dockerfile and scripts for improved WOL configuration and error handling
This commit is contained in:
@@ -3,10 +3,8 @@ FROM alpine:3.20
|
|||||||
|
|
||||||
# Install minimal tooling
|
# Install minimal tooling
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
bash curl ca-certificates \
|
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing wol \
|
||||||
docker-cli inotify-tools procps \
|
&& apk add --no-cache bash curl ca-certificates
|
||||||
busybox-extras iputils \
|
|
||||||
wakeonlan ethtool
|
|
||||||
|
|
||||||
# Copy script
|
# Copy script
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
13
compose.yaml
13
compose.yaml
@@ -2,19 +2,16 @@ services:
|
|||||||
auto-boot-ollama-host:
|
auto-boot-ollama-host:
|
||||||
build: .
|
build: .
|
||||||
container_name: auto-boot-ollama-host
|
container_name: auto-boot-ollama-host
|
||||||
|
network_mode: host
|
||||||
environment:
|
environment:
|
||||||
# customize as needed
|
# customize as needed
|
||||||
CONTAINER_NAME: "paperless-ai"
|
CONTAINER_NAME: "paperless-ai"
|
||||||
OLLAMA_HOST: "192.168.222.12"
|
OLLAMA_HOST: "192.168.222.12"
|
||||||
OLLAMA_PORT: "11434"
|
OLLAMA_PORT: "11434"
|
||||||
SINCE: "0s"
|
SINCE: "0s"
|
||||||
# WOL_MAC: "AA:BB:CC:DD:EE:FF"
|
WOL_MAC: "AA:BB:CC:DD:EE:FF" # set this
|
||||||
|
#WOL_BCAST: "192.168.222.255" # optional (defaults unten)
|
||||||
|
#WOL_PORT: "9" # optional
|
||||||
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
restart: unless-stopped
|
|
||||||
# Optional: network if you need special routing to OLLAMA_HOST
|
|
||||||
# networks:
|
|
||||||
# - hostnet
|
|
||||||
# networks:
|
|
||||||
# hostnet:
|
|
||||||
# external: true
|
|
||||||
|
|||||||
@@ -11,14 +11,23 @@ OLLAMA_HOST="${OLLAMA_HOST:-192.168.222.12}"
|
|||||||
OLLAMA_PORT="${OLLAMA_PORT:-11434}"
|
OLLAMA_PORT="${OLLAMA_PORT:-11434}"
|
||||||
ERROR_PATTERN="${ERROR_PATTERN:-Error: \\[ERROR\\] Document analysis failed: connect EHOSTUNREACH ${OLLAMA_HOST}:${OLLAMA_PORT}}"
|
ERROR_PATTERN="${ERROR_PATTERN:-Error: \\[ERROR\\] Document analysis failed: connect EHOSTUNREACH ${OLLAMA_HOST}:${OLLAMA_PORT}}"
|
||||||
|
|
||||||
|
WOL_MAC="${WOL_MAC:-}"
|
||||||
|
WOL_BCAST="${WOL_BCAST:-255.255.255.255}"
|
||||||
|
WOL_PORT="${WOL_PORT:-9}"
|
||||||
|
|
||||||
DOCKER_CLI="${DOCKER_CLI:-docker}" # docker CLI binary name
|
DOCKER_CLI="${DOCKER_CLI:-docker}" # docker CLI binary name
|
||||||
WOL_CMD="${WOL_CMD:-wakeonlan}" # or "etherwake -i eth0 $WOL_MAC"
|
|
||||||
NC_CMD="${NC_CMD:-nc}" # netcat
|
NC_CMD="${NC_CMD:-nc}" # netcat
|
||||||
WOL_MAC="${WOL_MAC:-}" # optional: MAC to WOL
|
WOL_MAC="${WOL_MAC:-}" # optional: MAC to WOL
|
||||||
SINCE="${SINCE:-0s}" # logs window (e.g., 5m)
|
SINCE="${SINCE:-0s}" # logs window (e.g., 5m)
|
||||||
|
|
||||||
log() { printf '[%(%F %T)T] %s\n' -1 "$*"; }
|
log() { printf '[%(%F %T)T] %s\n' -1 "$*"; }
|
||||||
|
|
||||||
|
send_wol() {
|
||||||
|
# 'wol' can send to a specific broadcast IP and UDP port
|
||||||
|
wol -i "$WOL_BCAST" -p "$WOL_PORT" "$WOL_MAC" || true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Basic pre-flight: show which container is watched
|
# Basic pre-flight: show which container is watched
|
||||||
log "Watching logs for container='${CONTAINER_NAME}' since='${SINCE}'"
|
log "Watching logs for container='${CONTAINER_NAME}' since='${SINCE}'"
|
||||||
log "Looking for pattern: ${ERROR_PATTERN}"
|
log "Looking for pattern: ${ERROR_PATTERN}"
|
||||||
@@ -29,6 +38,12 @@ while IFS= read -r line; do
|
|||||||
# echo "$line" # uncomment for debugging
|
# echo "$line" # uncomment for debugging
|
||||||
if echo "$line" | grep -qE "${ERROR_PATTERN}"; then
|
if echo "$line" | grep -qE "${ERROR_PATTERN}"; then
|
||||||
log "Detected EHOSTUNREACH for Ollama (${OLLAMA_HOST}:${OLLAMA_PORT})."
|
log "Detected EHOSTUNREACH for Ollama (${OLLAMA_HOST}:${OLLAMA_PORT})."
|
||||||
|
|
||||||
|
# ... in your remediation block:
|
||||||
|
if [[ -n "$WOL_MAC" ]]; then
|
||||||
|
log "Sending WOL to $WOL_MAC via ${WOL_BCAST}:${WOL_PORT}"
|
||||||
|
send_wol
|
||||||
|
fi
|
||||||
# --- remediation examples (optional) ---
|
# --- remediation examples (optional) ---
|
||||||
# if [[ -n "$WOL_MAC" ]]; then
|
# if [[ -n "$WOL_MAC" ]]; then
|
||||||
# log "Sending WOL to ${WOL_MAC}"
|
# log "Sending WOL to ${WOL_MAC}"
|
||||||
|
|||||||
Reference in New Issue
Block a user