10696600cSBjoern A. Zeeb#!/bin/sh 20696600cSBjoern A. Zeeb# 30696600cSBjoern A. Zeeb# 40696600cSBjoern A. Zeeb 50696600cSBjoern A. Zeeb# PROVIDE: accounting 60696600cSBjoern A. Zeeb# REQUIRE: mountcritremote 70696600cSBjoern A. Zeeb# BEFORE: DAEMON 80696600cSBjoern A. Zeeb# KEYWORD: nojail 90696600cSBjoern A. Zeeb 100696600cSBjoern A. Zeeb. /etc/rc.subr 110696600cSBjoern A. Zeeb 120696600cSBjoern A. Zeebname="accounting" 130696600cSBjoern A. Zeebrcvar="accounting_enable" 140696600cSBjoern A. Zeebaccounting_command="/usr/sbin/accton" 150696600cSBjoern A. Zeebaccounting_file="/var/account/acct" 160696600cSBjoern A. Zeeb 170696600cSBjoern A. Zeebextra_commands="rotate_log" 180696600cSBjoern A. Zeeb 190696600cSBjoern A. Zeebstart_cmd="accounting_start" 200696600cSBjoern A. Zeebstop_cmd="accounting_stop" 210696600cSBjoern A. Zeebrotate_log_cmd="accounting_rotate_log" 220696600cSBjoern A. Zeeb 231e121c3eSIan Leporecreate_accounting_file() 241e121c3eSIan Lepore{ 251e121c3eSIan Lepore install -o root -g wheel -m 0640 /dev/null "${accounting_file}" 261e121c3eSIan Lepore} 271e121c3eSIan Lepore 280696600cSBjoern A. Zeebaccounting_start() 290696600cSBjoern A. Zeeb{ 300696600cSBjoern A. Zeeb local _dir 310696600cSBjoern A. Zeeb 320696600cSBjoern A. Zeeb _dir="${accounting_file%/*}" 330696600cSBjoern A. Zeeb if [ ! -d "$_dir" ]; then 341e121c3eSIan Lepore if ! mkdir -p -m 0750 "$_dir"; then 350696600cSBjoern A. Zeeb err 1 "Could not create $_dir." 360696600cSBjoern A. Zeeb fi 370696600cSBjoern A. Zeeb fi 380696600cSBjoern A. Zeeb 390696600cSBjoern A. Zeeb if [ ! -e "$accounting_file" ]; then 400696600cSBjoern A. Zeeb echo -n "Creating accounting file ${accounting_file}" 411e121c3eSIan Lepore create_accounting_file 420696600cSBjoern A. Zeeb echo '.' 430696600cSBjoern A. Zeeb fi 440696600cSBjoern A. Zeeb 450696600cSBjoern A. Zeeb echo "Turning on accounting." 460696600cSBjoern A. Zeeb ${accounting_command} ${accounting_file} 470696600cSBjoern A. Zeeb} 480696600cSBjoern A. Zeeb 490696600cSBjoern A. Zeebaccounting_stop() 500696600cSBjoern A. Zeeb{ 510696600cSBjoern A. Zeeb echo "Turning off accounting." 520696600cSBjoern A. Zeeb ${accounting_command} 530696600cSBjoern A. Zeeb} 540696600cSBjoern A. Zeeb 550696600cSBjoern A. Zeebaccounting_rotate_log() 560696600cSBjoern A. Zeeb{ 571e121c3eSIan Lepore # Note that this function must handle being called as "onerotate_log" 581e121c3eSIan Lepore # (by the periodic scripts) when accounting is disabled, and handle 591e121c3eSIan Lepore # being called multiple times (by an admin making mistakes) without 601e121c3eSIan Lepore # anything having actually rotated the old .0 file out of the way. 610696600cSBjoern A. Zeeb 621e121c3eSIan Lepore if [ -e "${accounting_file}.0" ]; then 631e121c3eSIan Lepore err 1 "Cannot rotate accounting log, ${accounting_file}.0 already exists." 641e121c3eSIan Lepore fi 650696600cSBjoern A. Zeeb 661e121c3eSIan Lepore if [ ! -e "${accounting_file}" ]; then 671e121c3eSIan Lepore err 1 "Cannot rotate accounting log, ${accounting_file} does not exist." 680696600cSBjoern A. Zeeb fi 690696600cSBjoern A. Zeeb 700696600cSBjoern A. Zeeb mv ${accounting_file} ${accounting_file}.0 710696600cSBjoern A. Zeeb 720696600cSBjoern A. Zeeb if checkyesno accounting_enable; then 731e121c3eSIan Lepore create_accounting_file 741e121c3eSIan Lepore ${accounting_command} "${accounting_file}" 750696600cSBjoern A. Zeeb fi 760696600cSBjoern A. Zeeb} 770696600cSBjoern A. Zeeb 780696600cSBjoern A. Zeebload_rc_config $name 79*f99f0ee1SAlexander Leidinger 80*f99f0ee1SAlexander Leidinger# doesn't make sense to run in a svcj: jail can't manipulate accounting 81*f99f0ee1SAlexander Leidingeraccounting_svcj="NO" 82*f99f0ee1SAlexander Leidinger 830696600cSBjoern A. Zeebrun_rc_command "$1" 84