#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides:          opendnssec-enforcer
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: OpenDNSSEC Enforcer
# Description:       Daemon to create and enforce DNSSEC KASP policy
### END INIT INFO

DAEMON=/usr/sbin/ods-enforcerd
DESC="OpenDNSSEC Enforcer"
PIDFILE=/run/opendnssec/enforcerd.pid

do_tmpfiles() {
    local type path mode user group

    TMPFILES=/usr/lib/tmpfiles.d/$1.conf

    if [ -r "$TMPFILES" ]; then
        while read -r type path mode user group age arg; do
            if [ "$type" = "d" ]; then
                install -d -m "$mode" -o "$user" -g "$group" "$path"
            fi
        done < "$TMPFILES"
    fi
}

check_service_disabled()
{
    # Prevent startup if this file exists
    if [ -e /etc/opendnssec/prevent-startup ]; then
	log_action_msg "Service $DESC is disabled (/etc/opendnssec/prevent-startup)"
	exit 0
    fi
}

do_start_prepare() {
    check_service_disabled
    do_tmpfiles "$(basename "$0")"
    DAEMON_ARGS="$DAEMON_ARGS $ODS_ENFORCERD_OPT"
}

do_restart_prepare() {
    do_start_prepare "$@"
}
