#!/bin/sh /etc/rc.common
# nomad-api: TLS HTTPS daemon for the iOS companion app.
# Listens on LAN-only by default (see /etc/config/nomad-api). PSK and
# tokens live under /persist/nomad/api/.
#
# Why START=80: must come up after netifd has assigned the LAN IP, but
# before nomad-buttond (START=85) so the LCD pair-flow can reach a
# running API. STOP=15 so it's brought down before persistence-touching
# services on shutdown.

START=80
STOP=15
USE_PROCD=1

NOMAD_HOME="/etc/nomad"

start_service() {
    procd_open_instance
    procd_set_param command sh -c "PYTHONPATH=$NOMAD_HOME exec python3 -m nomad.api"
    # Give the process a fresh respawn budget after a crash but back
    # off if it keeps failing (procd default tightening).
    procd_set_param respawn 10 5 5
    procd_set_param stdout 1
    procd_set_param stderr 1
    procd_close_instance
}
