#!/bin/bash
# emhttp event: array is up. Start the MCP server if the service is enabled.
CFG="/boot/config/plugins/unraid-mcp/unraid-mcp.cfg"
# shellcheck source=/dev/null
[ -f "$CFG" ] && source "$CFG"
[ "${SERVICE}" = "enabled" ] || exit 0

for attempt in 1 2 3; do
    /etc/rc.d/rc.unraid-mcp start && exit 0
    sleep $((attempt * 2))
done
echo "unraid-mcp: failed to start after 3 attempts" >&2
exit 1
