#!/bin/sh
#
# $NetBSD: asterisk.sh,v 1.1 2025/10/27 06:58:37 jnemeth Exp $
#
# PROVIDE: asterisk
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# You will need to set some variables in /etc/rc.conf to start Asterisk:
#
# asterisk=YES

if [ -f /etc/rc.subr ]
then
	. /etc/rc.subr
fi

name="asterisk"
rcvar=$name
command="/usr/pkg/sbin/asterisk"
pidfile=/var/run/asterisk/${name}.pid
required_files="/usr/pkg/etc/asterisk/asterisk.conf"
extra_commands="reload"
start_precmd=asterisk_prestart

auser="asterisk"
agroup="asterisk"
command_args="-U $auser -G $agroup -n"

asterisk_prestart() {
	if test ! -d /var/run/asterisk; then
		mkdir /var/run/asterisk
	fi
	chown $auser:$agroup /var/run/asterisk
	chmod 0755 /var/run/asterisk
}

stop_cmd="$command -nr -x 'core stop gracefully' >/dev/null"
reload_cmd="$command -nr -x 'core reload' >/dev/null"
asterisk_nice="-20"

load_rc_config $name
run_rc_command "$1"
