#!/usr/bin/env bash
# onx-ols-reload — Restart OpenLiteSpeed (OLS requires restart, not reload, for vhost changes).
#
# Output: {"reloaded": true}
# Exit: 0=ok, 2=reload-failed, 3=lsws-not-installed

set -euo pipefail

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
# shellcheck source=_lib/common.sh
source "${SCRIPT_DIR}/_lib/common.sh"

LSWS_BASE="/usr/local/lsws"
LSWS_CTL="${LSWS_BASE}/bin/lswsctrl"

[[ -d "${LSWS_BASE}" ]] || onx_die 3 "OpenLiteSpeed not installed: ${LSWS_BASE} not found"
[[ -x "${LSWS_CTL}" ]] || onx_die 3 "lswsctrl not found: ${LSWS_CTL}"

if ! "${LSWS_CTL}" restart >/dev/null 2>&1; then
  onx_die 2 "lswsctrl restart failed"
fi

onx_json_out "reloaded" "true"
