accounting revision 234927
110228Syan#!/bin/sh 211926Sserb# 310228Syan# $FreeBSD: head/etc/rc.d/accounting 234927 2012-05-02 14:25:39Z jhb $ 410228Syan# 510228Syan 610228Syan# PROVIDE: accounting 710228Syan# REQUIRE: mountcritremote 810228Syan# BEFORE: DAEMON 910228Syan# KEYWORD: nojail 1010228Syan 1110228Syan. /etc/rc.subr 1210228Syan 1310228Syanname="accounting" 1410228Syanrcvar="accounting_enable" 1510228Syanaccounting_command="/usr/sbin/accton" 1610228Syanaccounting_file="/var/account/acct" 1710228Syan 1810228Syanextra_commands="rotate_log" 1910228Syan 2010228Syanstart_cmd="accounting_start" 2110228Syanstop_cmd="accounting_stop" 2210228Syanrotate_log_cmd="accounting_rotate_log" 2310228Syan 2410228Syanaccounting_start() 2510228Syan{ 2610228Syan local _dir 2710228Syan 2810228Syan _dir="${accounting_file%/*}" 2910228Syan if [ ! -d "$_dir" ]; then 3010228Syan if ! mkdir -p "$_dir"; then 3110228Syan err 1 "Could not create $_dir." 3210228Syan fi 3310228Syan fi 3410228Syan 3510228Syan if [ ! -e "$accounting_file" ]; then 3610228Syan echo -n "Creating accounting file ${accounting_file}" 3710228Syan touch "$accounting_file" 3810228Syan echo '.' 3910228Syan fi 4010228Syan chmod 644 "$accounting_file" 4110228Syan 4210228Syan echo "Turning on accounting." 4310228Syan ${accounting_command} ${accounting_file} 4410228Syan} 4510228Syan 4610228Syanaccounting_stop() 4710228Syan{ 4810228Syan echo "Turning off accounting." 4910228Syan ${accounting_command} 5010228Syan} 5110228Syan 5210228Syanaccounting_rotate_log() 5310228Syan{ 5410228Syan local _dir _file 5510228Syan 5610228Syan _dir="${accounting_file%/*}" 5710228Syan cd $_dir 5810228Syan 5910228Syan if checkyesno accounting_enable; then 6010228Syan _file=`mktemp newacct-XXXXX` 6110228Syan chmod 644 $_file 6210228Syan ${accounting_command} ${_dir}/${_file} 6310228Syan fi 6410228Syan 6510228Syan mv ${accounting_file} ${accounting_file}.0 6610228Syan 6710228Syan if checkyesno accounting_enable; then 6810228Syan mv $_file ${accounting_file} 6910228Syan fi 7010228Syan} 7110228Syan 7210228Syanload_rc_config $name 7310228Syanrun_rc_command "$1" 7410228Syan