#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: newsyslog
# Begin Isilon
# REQUIRE: FILESYSTEMS
# Removed requires: mountcritremote (dep loop)
# End Isilon

. /etc/rc.subr

name="newsyslog"
rcvar="newsyslog_enable"
# Begin Isilon
#required_files="/etc/newsyslog.conf"
# End Isilon
command="/usr/sbin/${name}"
# Begin Isilon
start_precmd="newsyslog_prestart"
# End Isilon
start_cmd="newsyslog_start"
stop_cmd=":"

# Begin Isilon
install_conf()
{
	[ -r /etc/newsyslog.conf ] && return

	#	Create all log files which do not already exist, and choose a
	#	newsyslog.conf based on the size of /var.
	#
	local var_size=$(/bin/df -b /var | awk '$NF == "/var" {print $2}')
	if [ -n "$var_size" -a "$var_size" -gt 1953125 ]; then
		# gmirror reports 2026136 sectors = 989 MiB = 1037 MB.
		ln -sf /etc/newsyslog.conf.1000MB /etc/newsyslog.conf
	else
		# imdd reports 1016286 sectors = 496 MiB = 520 MB.
		ln -sf /etc/newsyslog.conf.500MB /etc/newsyslog.conf
	fi
}

newsyslog_prestart()
{
	install_conf
}
# End Isilon

newsyslog_start()
{
	check_startmsgs && echo -n 'Creating and/or trimming log files'
	${command} ${rc_flags}
	check_startmsgs && echo '.'
}

load_rc_config $name
run_rc_command "$1"
