#!/sbin/openrc-run
# MarlinOS rsyslog (wake + turbo). OpenRC equivalent of
# pkg/linux/rsyslog.service. OpenRC has no equivalent of systemd's
# sandboxing directives, so this ships without them (ADR-0116 accepted gap
# — AppArmor confinement is dropped the same way on this target).

name="rsyslog"
description="rsyslog (MarlinOS — wake + turbo)"
command="/usr/sbin/rsyslogd"
command_args="-n -f /etc/rsyslog.conf"
supervisor="supervise-daemon"
respawn_delay=3
pidfile="/run/${RC_SVCNAME}.pid"

extra_started_commands="reload"

depend() {
	need net
	provide logger
}

reload() {
	# OpenRC has no stock reload verb, and many rsyslog configs lack an
	# ExecReload-equivalent hook anyway — send SIGHUP directly, the native
	# rsyslog reload mechanism (same reason waked's systemd path uses
	# `systemctl kill --signal=HUP` instead of `systemctl reload`).
	ebegin "Reloading ${name} (SIGHUP)"
	start-stop-daemon --signal HUP --pidfile "${pidfile}"
	eend $?
}

start_pre() {
	# systemd's RuntimeDirectory=/StateDirectory=rsyslog equivalent —
	# rsyslog.conf's $WorkDirectory points at /var/spool/rsyslog, which
	# nothing else creates on this target (this package displaces rather
	# than co-installs with Alpine's own rsyslog, which would normally own
	# that directory).
	checkpath -d -m 0755 /var/spool/rsyslog
}
