#!/sbin/openrc-run
# WAKE Web SOC Console (NiceGUI UI atop waked-collector). OpenRC equivalent
# of pkg/linux/wakeweb.service. See waked-edge.initd for the OpenRC
# hardening/cgroup caveats — PrivateTmp/ProtectSystem/ReadWritePaths have
# no OpenRC equivalent and are dropped (ADR-0116 accepted gap). Ships
# disabled: the alpine postinstall does not `rc-update add` this service,
# matching the systemd unit's "enabled per-host via fleet" intent — though
# with no fleet on this target, enabling it is a manual operator step.

name="wakeweb"
description="WAKE Web SOC Console (NiceGUI UI atop waked-collector)"
command="/opt/wake/bin/wakeweb"
command_args="--config /etc/wake/config.toml"
command_user="wake:wake"
directory="/var/db/wake"
supervisor="supervise-daemon"
respawn_delay=5
pidfile="/run/${RC_SVCNAME}.pid"

rc_ulimit="-n 65536"
rc_cgroup_settings=" memory.max 1G "

depend() {
	need net
	after waked-collector
	use waked-collector
}

start_pre() {
	# Fleet-managed host secrets normally supply WAKE_MCP_TOKEN; optional
	# here since this target has no fleet, mirroring systemd's
	# EnvironmentFile=-/etc/marlinos/secrets.env (absent file = API stays
	# disabled, the secure default). `set -a` exports every variable the
	# file defines so supervise-daemon's spawned child actually inherits
	# them. Done here, not at top-level, so `status`/other actions never
	# touch the 0600 file.
	if [ -f /etc/marlinos/secrets.env ]; then
		set -a
		. /etc/marlinos/secrets.env
		set +a
	fi
}
