#!/bin/sh /etc/rc.common
# shellcheck disable=SC2034  # START/STOP/USE_PROCD/PROG are read by
# /etc/rc.common, which sources this file; they are never referenced here.
# SPDX-License-Identifier: Apache-2.0
# Copyright 2026 VolanticSystems

# After netifyd (START=50): appflowd tolerates the agent being absent and
# retries, but starting later avoids a pointless first reconnect cycle.
START=95
STOP=10

USE_PROCD=1
PROG=/usr/sbin/appflowd

start_service() {
	procd_open_instance appflowd
	procd_set_param command "$PROG"
	# Keep restarting on unexpected exit: 5 s settle, give up after 5 crashes
	# inside an hour so a genuinely broken build does not spin forever.
	procd_set_param respawn 3600 5 5
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_set_param pidfile /var/run/appflowd.pid
	procd_close_instance
}

service_triggers() {
	procd_add_reload_trigger "appflow"
}

reload_service() {
	# Configuration is read once at start-up; a reload is a restart.
	restart
}
