accounting revision 218961
1#!/bin/sh
2#
3# $FreeBSD: head/etc/rc.d/accounting 218961 2011-02-22 21:13:40Z dougb $
4#
5
6# PROVIDE: accounting
7# REQUIRE: mountcritremote
8# BEFORE: DAEMON
9# KEYWORD: nojail
10
11. /etc/rc.subr
12
13name="accounting"
14rcvar=`set_rcvar`
15accounting_command="/usr/sbin/accton"
16accounting_file="/var/account/acct"
17
18extra_commands="rotate_log"
19
20start_cmd="accounting_start"
21stop_cmd="accounting_stop"
22rotate_log_cmd="accounting_rotate_log"
23
24accounting_start()
25{
26	local _dir
27
28	_dir="${accounting_file%/*}"
29	if [ ! -d "$_dir" ]; then
30		if ! mkdir -p "$_dir"; then
31			err 1 "Could not create $_dir."
32		fi
33	fi
34
35	if [ ! -e "$accounting_file" ]; then
36		echo -n "Creating accounting file ${accounting_file}"
37		touch "$accounting_file"
38		echo '.'
39	fi
40	chmod 644 "$accounting_file"
41
42	echo "Turning on accounting."
43	${accounting_command} ${accounting_file}
44}
45
46accounting_stop()
47{
48	echo "Turning off accounting."
49	${accounting_command}
50}
51
52accounting_rotate_log()
53{
54	local _dir _file
55
56	_dir="${accounting_file%/*}"
57	cd $_dir
58
59	if checkyesno accounting_enable; then
60		_file=`mktemp newacct-XXXXX`
61		${accounting_command} ${_dir}/${_file}
62	fi
63
64	mv ${accounting_file} ${accounting_file}.0
65
66	if checkyesno accounting_enable; then
67		ln $_file ${accounting_file##*/}
68		${accounting_command} ${accounting_file}
69		unlink $_file
70	fi
71}
72
73load_rc_config $name
74run_rc_command "$1"
75