2001-06-16 07:16:14 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2002-06-13 22:14:37 +00:00
|
|
|
# $FreeBSD$
|
2001-06-16 07:16:14 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: accounting
|
2004-03-05 07:43:38 +00:00
|
|
|
# REQUIRE: mountcritremote
|
2002-06-13 22:14:37 +00:00
|
|
|
# BEFORE: DAEMON
|
2004-10-07 13:55:26 +00:00
|
|
|
# KEYWORD: nojail
|
2001-06-16 07:16:14 +00:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="accounting"
|
2012-01-14 02:18:41 +00:00
|
|
|
rcvar="accounting_enable"
|
2002-06-13 22:14:37 +00:00
|
|
|
accounting_command="/usr/sbin/accton"
|
|
|
|
accounting_file="/var/account/acct"
|
2011-02-22 21:13:40 +00:00
|
|
|
|
|
|
|
extra_commands="rotate_log"
|
|
|
|
|
2001-06-16 07:16:14 +00:00
|
|
|
start_cmd="accounting_start"
|
|
|
|
stop_cmd="accounting_stop"
|
2011-02-22 21:13:40 +00:00
|
|
|
rotate_log_cmd="accounting_rotate_log"
|
2001-06-16 07:16:14 +00:00
|
|
|
|
|
|
|
accounting_start()
|
|
|
|
{
|
2006-12-30 22:53:20 +00:00
|
|
|
local _dir
|
|
|
|
|
2011-02-22 21:13:40 +00:00
|
|
|
_dir="${accounting_file%/*}"
|
|
|
|
if [ ! -d "$_dir" ]; then
|
2004-01-17 11:25:16 +00:00
|
|
|
if ! mkdir -p "$_dir"; then
|
2011-02-22 21:13:40 +00:00
|
|
|
err 1 "Could not create $_dir."
|
2002-06-13 22:14:37 +00:00
|
|
|
fi
|
2004-01-17 11:25:16 +00:00
|
|
|
fi
|
2011-02-22 21:13:40 +00:00
|
|
|
|
2004-01-17 11:25:16 +00:00
|
|
|
if [ ! -e "$accounting_file" ]; then
|
2011-02-22 21:13:40 +00:00
|
|
|
echo -n "Creating accounting file ${accounting_file}"
|
2004-01-17 11:25:16 +00:00
|
|
|
touch "$accounting_file"
|
2011-02-22 21:13:40 +00:00
|
|
|
echo '.'
|
2004-01-17 11:25:16 +00:00
|
|
|
fi
|
2011-02-22 21:13:40 +00:00
|
|
|
chmod 644 "$accounting_file"
|
2002-06-13 22:14:37 +00:00
|
|
|
|
|
|
|
echo "Turning on accounting."
|
|
|
|
${accounting_command} ${accounting_file}
|
2001-06-16 07:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
accounting_stop()
|
|
|
|
{
|
|
|
|
echo "Turning off accounting."
|
2002-06-13 22:14:37 +00:00
|
|
|
${accounting_command}
|
2001-06-16 07:16:14 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 21:13:40 +00:00
|
|
|
accounting_rotate_log()
|
|
|
|
{
|
|
|
|
local _dir _file
|
|
|
|
|
|
|
|
_dir="${accounting_file%/*}"
|
|
|
|
cd $_dir
|
|
|
|
|
|
|
|
if checkyesno accounting_enable; then
|
|
|
|
_file=`mktemp newacct-XXXXX`
|
2011-02-24 06:28:48 +00:00
|
|
|
chmod 644 $_file
|
2011-02-22 21:13:40 +00:00
|
|
|
${accounting_command} ${_dir}/${_file}
|
|
|
|
fi
|
|
|
|
|
|
|
|
mv ${accounting_file} ${accounting_file}.0
|
|
|
|
|
|
|
|
if checkyesno accounting_enable; then
|
2012-05-02 14:25:39 +00:00
|
|
|
mv $_file ${accounting_file}
|
2011-02-22 21:13:40 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2001-06-16 07:16:14 +00:00
|
|
|
load_rc_config $name
|
|
|
|
run_rc_command "$1"
|