137 lines
3.1 KiB
Bash
Executable File
137 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
repo_root="$(cd "${script_dir}/.." && pwd)"
|
|
|
|
broker_dir="/opt/qortal-broker"
|
|
env_file=""
|
|
compose_file=""
|
|
|
|
usage() {
|
|
cat <<USAGE
|
|
Usage: ./scripts/stop-host-nextcloud-hybrid.sh [options]
|
|
|
|
Stop the active host-hybrid sidecar services without removing volumes.
|
|
|
|
Options:
|
|
--broker-dir <path> Broker runtime dir (default: /opt/qortal-broker)
|
|
--env-file <path> Env file override (default: <broker-dir>/.env)
|
|
--compose-file <path> Compose file override (default: <broker-dir>/docker-compose.yml)
|
|
-h, --help Show this help
|
|
USAGE
|
|
}
|
|
|
|
read_kv() {
|
|
local key="$1"
|
|
local file="$2"
|
|
local line=""
|
|
if [[ -z "${file}" || ! -f "${file}" ]]; then
|
|
return 1
|
|
fi
|
|
line="$(grep -m1 -E "^${key}=" "${file}" 2>/dev/null || true)"
|
|
[[ -n "${line}" ]] || return 1
|
|
printf '%s' "${line#*=}"
|
|
}
|
|
|
|
resolve_path() {
|
|
local raw="${1:-}"
|
|
if [[ -z "${raw}" ]]; then
|
|
printf '%s' ""
|
|
return 0
|
|
fi
|
|
if [[ "${raw}" == /* ]]; then
|
|
printf '%s' "${raw}"
|
|
return 0
|
|
fi
|
|
printf '%s' "${repo_root}/${raw}"
|
|
}
|
|
|
|
ensure_docker_cmd() {
|
|
if command -v docker >/dev/null 2>&1 && docker info >/dev/null 2>&1; then
|
|
DOCKER_CMD=(docker)
|
|
return 0
|
|
fi
|
|
if command -v sudo >/dev/null 2>&1; then
|
|
if sudo -n docker info >/dev/null 2>&1 || sudo docker info >/dev/null 2>&1; then
|
|
DOCKER_CMD=(sudo docker)
|
|
return 0
|
|
fi
|
|
fi
|
|
echo "docker access is required to stop the host-hybrid stack." >&2
|
|
exit 1
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--broker-dir)
|
|
broker_dir="${2:-}"
|
|
shift 2
|
|
;;
|
|
--broker-dir=*)
|
|
broker_dir="${1#*=}"
|
|
shift
|
|
;;
|
|
--env-file)
|
|
env_file="${2:-}"
|
|
shift 2
|
|
;;
|
|
--env-file=*)
|
|
env_file="${1#*=}"
|
|
shift
|
|
;;
|
|
--compose-file)
|
|
compose_file="${2:-}"
|
|
shift 2
|
|
;;
|
|
--compose-file=*)
|
|
compose_file="${1#*=}"
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1" >&2
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
broker_dir="$(resolve_path "${broker_dir}")"
|
|
env_file="${env_file:-${broker_dir}/.env}"
|
|
compose_file="${compose_file:-${broker_dir}/docker-compose.yml}"
|
|
env_file="$(resolve_path "${env_file}")"
|
|
compose_file="$(resolve_path "${compose_file}")"
|
|
|
|
if [[ ! -f "${env_file}" ]]; then
|
|
echo "Missing env file: ${env_file}" >&2
|
|
exit 1
|
|
fi
|
|
if [[ ! -f "${compose_file}" ]]; then
|
|
echo "Missing compose file: ${compose_file}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
source "${script_dir}/lib-compose-project.sh"
|
|
export_compose_project_name_from_env "${env_file}" || true
|
|
|
|
ensure_docker_cmd
|
|
|
|
profiles="$(read_kv "COMPOSE_PROFILES" "${env_file}" || true)"
|
|
services=("broker_db" "broker")
|
|
if [[ ",${profiles}," == *",external-auth,"* ]]; then
|
|
services+=("external_auth")
|
|
fi
|
|
if [[ ",${profiles}," == *",qortal,"* ]]; then
|
|
services+=("qortal_node")
|
|
fi
|
|
|
|
echo "Stopping host-hybrid services:"
|
|
printf ' %s\n' "${services[@]}"
|
|
"${DOCKER_CMD[@]}" compose -f "${compose_file}" --env-file "${env_file}" stop "${services[@]}"
|
|
|
|
echo "Host-hybrid services stopped."
|