Init
This commit is contained in:
22
Dockerfile
Normal file
22
Dockerfile
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
FROM alpine:3.20
|
||||||
|
|
||||||
|
# Install minimal tooling
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
bash curl ca-certificates \
|
||||||
|
docker-cli inotify-tools procps \
|
||||||
|
busybox-extras iputils \
|
||||||
|
wakeonlan ethtool
|
||||||
|
|
||||||
|
# Copy script
|
||||||
|
WORKDIR /app
|
||||||
|
COPY scripts/auto-boot-ollama-pc.sh /usr/local/bin/auto-boot-ollama-pc.sh
|
||||||
|
RUN chmod +x /usr/local/bin/auto-boot-ollama-pc.sh
|
||||||
|
|
||||||
|
# Environment defaults (can be overridden by compose/Komodo)
|
||||||
|
ENV CONTAINER_NAME=paperless-ai \
|
||||||
|
OLLAMA_HOST=192.168.222.12 \
|
||||||
|
OLLAMA_PORT=11434 \
|
||||||
|
SINCE=0s
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/auto-boot-ollama-pc.sh"]
|
||||||
20
compose.yaml
Normal file
20
compose.yaml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
services:
|
||||||
|
auto-boot-ollama-host:
|
||||||
|
build: .
|
||||||
|
container_name: auto-boot-ollama-host
|
||||||
|
environment:
|
||||||
|
# customize as needed
|
||||||
|
CONTAINER_NAME: "paperless-ai"
|
||||||
|
OLLAMA_HOST: "192.168.222.12"
|
||||||
|
OLLAMA_PORT: "11434"
|
||||||
|
SINCE: "0s"
|
||||||
|
# WOL_MAC: "AA:BB:CC:DD:EE:FF"
|
||||||
|
volumes:
|
||||||
|
- /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
|
||||||
43
scripts/auto-boot-ollama-host.sh
Normal file
43
scripts/auto-boot-ollama-host.sh
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
# Purpose: Watch docker logs of a host container and react to an error pattern.
|
||||||
|
# Notes:
|
||||||
|
# - This runs *inside* a container with /var/run/docker.sock mounted.
|
||||||
|
# - Requires docker CLI inside this container.
|
||||||
|
|
||||||
|
# ---- Config via env (with sane defaults) ----
|
||||||
|
CONTAINER_NAME="${CONTAINER_NAME:-paperless-ai}"
|
||||||
|
OLLAMA_HOST="${OLLAMA_HOST:-192.168.222.12}"
|
||||||
|
OLLAMA_PORT="${OLLAMA_PORT:-11434}"
|
||||||
|
ERROR_PATTERN="${ERROR_PATTERN:-Error: \\[ERROR\\] Document analysis failed: connect EHOSTUNREACH ${OLLAMA_HOST}:${OLLAMA_PORT}}"
|
||||||
|
|
||||||
|
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
|
||||||
|
WOL_MAC="${WOL_MAC:-}" # optional: MAC to WOL
|
||||||
|
SINCE="${SINCE:-0s}" # logs window (e.g., 5m)
|
||||||
|
|
||||||
|
log() { printf '[%(%F %T)T] %s\n' -1 "$*"; }
|
||||||
|
|
||||||
|
# Basic pre-flight: show which container is watched
|
||||||
|
log "Watching logs for container='${CONTAINER_NAME}' since='${SINCE}'"
|
||||||
|
log "Looking for pattern: ${ERROR_PATTERN}"
|
||||||
|
|
||||||
|
# Stream logs and parse
|
||||||
|
"${DOCKER_CLI}" logs -f --since "${SINCE}" "${CONTAINER_NAME}" 2>&1 | \
|
||||||
|
while IFS= read -r line; do
|
||||||
|
# echo "$line" # uncomment for debugging
|
||||||
|
if echo "$line" | grep -qE "${ERROR_PATTERN}"; then
|
||||||
|
log "Detected EHOSTUNREACH for Ollama (${OLLAMA_HOST}:${OLLAMA_PORT})."
|
||||||
|
# --- remediation examples (optional) ---
|
||||||
|
# if [[ -n "$WOL_MAC" ]]; then
|
||||||
|
# log "Sending WOL to ${WOL_MAC}"
|
||||||
|
# $WOL_CMD "$WOL_MAC" || true
|
||||||
|
# fi
|
||||||
|
# until $NC_CMD -z "$OLLAMA_HOST" "$OLLAMA_PORT"; do
|
||||||
|
# log "Waiting for Ollama to be reachable..."
|
||||||
|
# sleep 2
|
||||||
|
# done
|
||||||
|
# log "Ollama reachable again."
|
||||||
|
fi
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user