178344Sobrien#!/bin/sh 278344Sobrien# 398184Sgordon# $FreeBSD$ 478344Sobrien# 578344Sobrien 678344Sobrien# PROVIDE: accounting 7126636Smtm# REQUIRE: mountcritremote 898184Sgordon# BEFORE: DAEMON 9136224Smtm# KEYWORD: nojail 1078344Sobrien 1178344Sobrien. /etc/rc.subr 1278344Sobrien 1378344Sobrienname="accounting" 14230099Sdougbrcvar="accounting_enable" 1598184Sgordonaccounting_command="/usr/sbin/accton" 1698184Sgordonaccounting_file="/var/account/acct" 17218961Sdougb 18218961Sdougbextra_commands="rotate_log" 19218961Sdougb 2078344Sobrienstart_cmd="accounting_start" 2178344Sobrienstop_cmd="accounting_stop" 22218961Sdougbrotate_log_cmd="accounting_rotate_log" 2378344Sobrien 2478344Sobrienaccounting_start() 2578344Sobrien{ 26165664Syar local _dir 27165664Syar 28218961Sdougb _dir="${accounting_file%/*}" 29218961Sdougb if [ ! -d "$_dir" ]; then 30124627Smtm if ! mkdir -p "$_dir"; then 31218961Sdougb err 1 "Could not create $_dir." 3298184Sgordon fi 33124627Smtm fi 34218961Sdougb 35124627Smtm if [ ! -e "$accounting_file" ]; then 36218961Sdougb echo -n "Creating accounting file ${accounting_file}" 37124627Smtm touch "$accounting_file" 38218961Sdougb echo '.' 39124627Smtm fi 40218961Sdougb chmod 644 "$accounting_file" 4198184Sgordon 4298184Sgordon echo "Turning on accounting." 4398184Sgordon ${accounting_command} ${accounting_file} 4478344Sobrien} 4578344Sobrien 4678344Sobrienaccounting_stop() 4778344Sobrien{ 4878344Sobrien echo "Turning off accounting." 4998184Sgordon ${accounting_command} 5078344Sobrien} 5178344Sobrien 52218961Sdougbaccounting_rotate_log() 53218961Sdougb{ 54218961Sdougb local _dir _file 55218961Sdougb 56218961Sdougb _dir="${accounting_file%/*}" 57218961Sdougb cd $_dir 58218961Sdougb 59218961Sdougb if checkyesno accounting_enable; then 60218961Sdougb _file=`mktemp newacct-XXXXX` 61218986Sdougb chmod 644 $_file 62218961Sdougb ${accounting_command} ${_dir}/${_file} 63218961Sdougb fi 64218961Sdougb 65218961Sdougb mv ${accounting_file} ${accounting_file}.0 66218961Sdougb 67218961Sdougb if checkyesno accounting_enable; then 68234927Sjhb mv $_file ${accounting_file} 69218961Sdougb fi 70218961Sdougb} 71218961Sdougb 7278344Sobrienload_rc_config $name 7378344Sobrienrun_rc_command "$1" 74