1#!/bin/sh 2# 3# $FreeBSD: head/etc/rc.d/accounting 234927 2012-05-02 14:25:39Z jhb $ 4# 5 6# PROVIDE: accounting 7# REQUIRE: mountcritremote 8# BEFORE: DAEMON 9# KEYWORD: nojail 10 11. /etc/rc.subr 12 13name="accounting" 14rcvar="accounting_enable" 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 chmod 644 $_file 62 ${accounting_command} ${_dir}/${_file} 63 fi 64 65 mv ${accounting_file} ${accounting_file}.0 66 67 if checkyesno accounting_enable; then 68 mv $_file ${accounting_file} 69 fi 70} 71 72load_rc_config $name 73run_rc_command "$1" 74