xref: /dragonfly/etc/rc.d/accounting (revision 2de78d78)
19c600e7dSMatthew Dillon#!/bin/sh
29c600e7dSMatthew Dillon#
3*2de78d78SAaron LI# $FreeBSD: head/etc/rc.d/accounting 234927 2012-05-02 14:25:39Z jhb $
49c600e7dSMatthew Dillon#
59c600e7dSMatthew Dillon
69c600e7dSMatthew Dillon# PROVIDE: accounting
7a8ed1681SJoerg Sonnenberger# REQUIRE: mountcritremote
89c600e7dSMatthew Dillon# BEFORE: DAEMON
9*2de78d78SAaron LI# KEYWORD: nojail
109c600e7dSMatthew Dillon
119c600e7dSMatthew Dillon. /etc/rc.subr
129c600e7dSMatthew Dillon
139c600e7dSMatthew Dillonname="accounting"
14*2de78d78SAaron LIrcvar="accounting_enable"
159c600e7dSMatthew Dillonaccounting_command="/usr/sbin/accton"
169c600e7dSMatthew Dillonaccounting_file="/var/account/acct"
17*2de78d78SAaron LI
18*2de78d78SAaron LIextra_commands="rotate_log"
19*2de78d78SAaron LI
209c600e7dSMatthew Dillonstart_cmd="accounting_start"
219c600e7dSMatthew Dillonstop_cmd="accounting_stop"
22*2de78d78SAaron LIrotate_log_cmd="accounting_rotate_log"
239c600e7dSMatthew Dillon
249c600e7dSMatthew Dillonaccounting_start()
259c600e7dSMatthew Dillon{
26*2de78d78SAaron LI	local _dir
27*2de78d78SAaron LI
28*2de78d78SAaron LI	_dir="${accounting_file%/*}"
29*2de78d78SAaron LI	if [ ! -d "$_dir" ]; then
309c600e7dSMatthew Dillon		if ! mkdir -p "$_dir"; then
31*2de78d78SAaron LI			err 1 "Could not create $_dir."
329c600e7dSMatthew Dillon		fi
339c600e7dSMatthew Dillon	fi
34*2de78d78SAaron LI
359c600e7dSMatthew Dillon	if [ ! -e "$accounting_file" ]; then
36*2de78d78SAaron LI		echo -n "Creating accounting file ${accounting_file}"
379c600e7dSMatthew Dillon		touch "$accounting_file"
38*2de78d78SAaron LI		echo '.'
399c600e7dSMatthew Dillon	fi
40*2de78d78SAaron LI	chmod 644 "$accounting_file"
41*2de78d78SAaron LI
429c600e7dSMatthew Dillon	echo "Turning on accounting."
439c600e7dSMatthew Dillon	${accounting_command} ${accounting_file}
449c600e7dSMatthew Dillon}
459c600e7dSMatthew Dillon
469c600e7dSMatthew Dillonaccounting_stop()
479c600e7dSMatthew Dillon{
489c600e7dSMatthew Dillon	echo "Turning off accounting."
499c600e7dSMatthew Dillon	${accounting_command}
509c600e7dSMatthew Dillon}
519c600e7dSMatthew Dillon
52*2de78d78SAaron LIaccounting_rotate_log()
53*2de78d78SAaron LI{
54*2de78d78SAaron LI	local _dir _file
55*2de78d78SAaron LI
56*2de78d78SAaron LI	_dir="${accounting_file%/*}"
57*2de78d78SAaron LI	cd $_dir
58*2de78d78SAaron LI
59*2de78d78SAaron LI	if checkyesno accounting_enable; then
60*2de78d78SAaron LI		_file=`mktemp newacct-XXXXX`
61*2de78d78SAaron LI		chmod 644 $_file
62*2de78d78SAaron LI		${accounting_command} ${_dir}/${_file}
63*2de78d78SAaron LI	fi
64*2de78d78SAaron LI
65*2de78d78SAaron LI	mv ${accounting_file} ${accounting_file}.0
66*2de78d78SAaron LI
67*2de78d78SAaron LI	if checkyesno accounting_enable; then
68*2de78d78SAaron LI		mv $_file ${accounting_file}
69*2de78d78SAaron LI	fi
70*2de78d78SAaron LI}
71*2de78d78SAaron LI
729c600e7dSMatthew Dillonload_rc_config $name
739c600e7dSMatthew Dillonrun_rc_command "$1"
74