#!/sbin/openrc-run
# SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
# SPDX-License-Identifier: GPL-2.0-or-later
#
# OpenRC service for a Gitea act_runner (Docker executor) on Alpine.
#
# Install as /etc/init.d/act_runner (chmod +x). Single instance uses
# /etc/act_runner/config.yaml. For one runner per project, symlink this script
# and add a matching conf.d file:
#
#   ln -s act_runner /etc/init.d/act_runner.trx-rs
#   cp container/act_runner.confd.example /etc/conf.d/act_runner.trx-rs
#   $EDITOR /etc/conf.d/act_runner.trx-rs      # set runner_dir / runner_config
#   rc-update add act_runner.trx-rs default
#   rc-service act_runner.trx-rs start

description="Gitea Actions runner"

: "${runner_user:=act}"
: "${runner_dir:=/var/lib/act_runner}"
: "${runner_config:=/etc/act_runner/config.yaml}"

command="/usr/local/bin/act_runner"
command_args="daemon --config ${runner_config}"
# No group given, so supplementary groups (incl. docker) are initialised.
command_user="${runner_user}"
directory="${runner_dir}"

supervisor="supervise-daemon"
respawn_delay=5
respawn_max=0
pidfile="/run/${RC_SVCNAME}.pid"
output_log="/var/log/${RC_SVCNAME}.log"
error_log="/var/log/${RC_SVCNAME}.log"

depend() {
	need docker
	use net dns
}

start_pre() {
	checkpath -d -m 0750 -o "${runner_user}" "${runner_dir}"
	checkpath -f -m 0640 -o "${runner_user}" "${output_log}"
}
