#!/bin/sh

# PROVIDE: syz_ci
# REQUIRE: LOGIN

. /etc/rc.subr

command="${syz_ci_path}"
name="syz_ci"
pidfile="/var/run/${name}.pid"
rcvar="syz_ci_enable"
start_cmd="syz_ci_start"
stop_cmd="syz_ci_stop"

# syz-ci needs to be able to find the go executable.
PATH=${PATH}:/usr/local/bin

syz_ci_start()
{
	cd "${syz_ci_chdir}"
	daemon -f -o "${syz_ci_log}" -p ${pidfile} "${syz_ci_path}" ${syz_ci_flags}
}

syz_ci_stop()
{
	local _pid

	_pid=$(cat ${pidfile})
	kill -INT $_pid
	[ $? -eq 0 ] || return 1
	pwait -t 120s $_pid
}

load_rc_config $name
run_rc_command "$1"
