#!/bin/sh

# PROVIDE: ntopng
# REQUIRE: LOGIN netif mysql
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable ntopng:
#
# ntopng_enable (bool):		Set it to "YES" to enable ntopng
#				Default is "NO".
# ntopng_flags (flags):		Set extra flags to ntopng
#				Empty by default.
# ntopng_pidfile (path):	Path to the pidfile
#				Default /var/run/ntopng/ntopng.pid
#

. /etc/rc.subr

name=ntopng
desc="Monitors network traffic in realtime"
rcvar=ntopng_enable

load_rc_config $name

: ${ntopng_enable:=NO}
: ${ntopng_pidfile:=/var/run/ntopng/ntopng.pid}

httpdocs_path=/usr/local/share/ntopng/httpdocs
scripts_path=/usr/local/share/ntopng/scripts
callbacks_path=/usr/local/share/ntopng/scripts/callbacks
user_path=/usr/local/etc/ntopng-users.conf

start_precmd=ntopng_precmd
command=/usr/local/bin/ntopng
command_args="-U ntopng -G ${ntopng_pidfile} -1 ${httpdocs_path} -2 ${scripts_path} -3 ${callbacks_path} -e"

ntopng_precmd()
{
	local rundir=${ntopng_pidfile%/*}
	if [ ! -d $rundir ] ; then
		install -d -m 0755 -o ntopng -g ntopng $rundir
	fi
}

run_rc_command "$1"
