#!/usr/bin/env bash
# onx-postfix-reload — systemctl reload postfix
# stdin: {} (boş veya herhangi JSON)
# stdout: {"ok":true,"status":"active","message":"…"}

set -euo pipefail
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
source "${SCRIPT_DIR}/_lib/common.sh"

require_root

INPUT=$(cat)

if ! systemctl reload postfix 2>/dev/null; then
    json_fail 3 "systemctl reload postfix başarısız"
fi

STATUS=$(systemctl is-active postfix 2>/dev/null || echo "unknown")
UPTIME=$(systemctl show postfix -p ActiveEnterTimestamp --value 2>/dev/null || echo "")

json_ok "{\"ok\":true,\"status\":\"${STATUS}\",\"uptime\":\"${UPTIME}\",\"message\":\"Postfix reload edildi\"}"
