#!/bin/sh /etc/rc.common
# nomad-watchdog – periodic-tick scheduler for devices without an LCD.
#
# On LCD devices (Mudi 7) the same tick body runs inside
# /etc/init.d/nomad-buttond's 0.5 s watchdog. On every other GL.iNet
# device (Beryl, Slate, Flint, Brume, Marble, Spitz/Puli AX, ...) we
# install THIS service instead – same nomad.watchdog.tick_all() body,
# standalone process, no LCD dependency.
#
# install.sh deploys + enables this only when `nomad.hardware.detect()`
# reports has_lcd=False; on LCD devices buttond covers it and a
# second scheduler would be wasteful.
#
# START=85 – same slot as nomad-buttond so the boot-time
# `apply_sticky_at_boot()` chain runs at the same point in the boot
# sequence regardless of which scheduler is in use.

START=85
STOP=10
USE_PROCD=1

NOMAD_HOME="/etc/nomad"
INTERVAL="${INTERVAL:-2.0}"

start_service() {
    procd_open_instance
    procd_set_param command sh -c \
        "PYTHONPATH=$NOMAD_HOME exec python3 -m nomad.cli watchdog run --interval $INTERVAL"
    procd_set_param respawn 10 5 5
    procd_set_param stdout 1
    procd_set_param stderr 1
    procd_close_instance
}
