#!/bin/sh
#
# $FreeBSD: branches/2020Q1/www/unit/files/unitd.in 454295 2017-11-16 00:19:13Z osa $

# PROVIDE: unitd
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable nginx:
# unitd_enable (bool):          Set to "NO" by default.
#                               Set it to "YES" to enable unit
# unitd_sockfile (str):         Set to "" by default.
#                               Set it to "127.0.0.1:8443" to enable the unit control
#                               socket on the network address

. /etc/rc.subr

name="unitd"
rcvar=unitd_enable

command="/usr/sbin/unitd"
start_precmd=start_precmd

start_precmd()
{
    rm -f /var/run/unit/control.unit.sock
}

load_rc_config $name

# Default value
: ${unitd_sockfile=""}

pidfile=${unit_pidfile:-"/var/run/unit/unit.pid"}
unitd_enable=${unitd_enable:-YESO"}
sockfile=${unitd_sockfile}

if [ x${sockfile} != "x" ]
then
    command_args="--control ${sockfile}"
fi

run_rc_command "$1"
