Files

34 lines
1.0 KiB
Bash

#!/bin/sh
# Sourced by host lifecycle scripts; never grants Docker or device permissions.
DOCKER_QUERY_TIMEOUT_SECONDS=5
DOCKER_KILL_GRACE_SECONDS=1
report_error() {
printf '%s\n' "$1" >&2
if [ -n "${TRIM_TEMP_LOGFILE:-}" ]; then printf '%s\n' "$1" > "$TRIM_TEMP_LOGFILE"; fi
}
bounded_docker() {
for executable in docker timeout; do
if ! command -v "$executable" >/dev/null 2>&1; then
report_error "缺少 $executable,请检查飞牛 Docker 应用和系统工具。"
return 1
fi
done
if timeout -k "$DOCKER_KILL_GRACE_SECONDS" "$DOCKER_QUERY_TIMEOUT_SECONDS" docker "$@"; then
return 0
else
result=$?
fi
case "$result" in
124|137) report_error 'Docker 查询超时,请检查飞牛 Docker 服务;未启动或停止任何容器。' ;;
*) report_error 'Docker 查询失败,请检查服务是否启动及应用用户权限;未自动提权。' ;;
esac
return 1
}
preflight() {
bounded_docker info --format '{{.ServerVersion}}' >/dev/null || return 1
bounded_docker compose version >/dev/null || return 1
}