Date: Mon, 21 Feb 2011 23:28:30 -0800 From: Doug Barton <dougb@dougbarton.us> To: freebsd-hackers@FreeBSD.org Subject: Re: Problem with etc/periodic/daily/310.accounting Message-ID: <4D63659E.6010305@dougbarton.us> In-Reply-To: <4D6323D9.5090500@dougbarton.us> References: <4D6323D9.5090500@dougbarton.us>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------080201010908080508080504 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Ignore my last. The problem is that if /var/account/acct disappears then accounting stops. The attached is better, albeit more complicated. It also has the pleasant side effect of cleaning up /etc/rc.d/accounting a bit. I've confirmed that with this patch nothing is lost while the file is being switched: unlink - root pts/2 0.006 secs Mon Feb 21 23:23 sa - root pts/2 0.014 secs Mon Feb 21 23:23 gzip - root pts/2 0.014 secs Mon Feb 21 23:23 sh - root pts/2 0.099 secs Mon Feb 21 23:23 unlink - root pts/2 0.006 secs Mon Feb 21 23:23 accton - root pts/2 0.006 secs Mon Feb 21 23:23 ln - root pts/2 0.006 secs Mon Feb 21 23:23 mv - root pts/2 0.007 secs Mon Feb 21 23:23 accton - root pts/2 0.011 secs Mon Feb 21 23:23 Doug -- Nothin' ever doesn't change, but nothin' changes much. -- OK Go Breadth of IT experience, and depth of knowledge in the DNS. Yours for the right price. :) http://SupersetSolutions.com/ --------------080201010908080508080504 Content-Type: text/plain; name="310.accounting-2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="310.accounting-2.diff" Index: periodic/daily/310.accounting =================================================================== --- periodic/daily/310.accounting (revision 218938) +++ periodic/daily/310.accounting (working copy) @@ -41,13 +41,16 @@ m=$n n=$(($n - 1)) done - cp -pf acct acct.0 || rc=3 - sa -s $daily_accounting_flags || rc=3 + /etc/rc.d/accounting rotate_log || rc=3 + case "$daily_accounting_compress" in [Yy][Ee][Ss]) - gzip -f acct.0 || rc=3;; + gzip --keep -f acct.0 || rc=3;; esac + + sa -s $daily_accounting_flags /var/account/acct.0 && + unlink acct.0 || rc=3 fi;; *) rc=0;; Index: rc.d/accounting =================================================================== --- rc.d/accounting (revision 218938) +++ rc.d/accounting (working copy) @@ -14,30 +14,34 @@ rcvar=`set_rcvar` accounting_command="/usr/sbin/accton" accounting_file="/var/account/acct" + +extra_commands="rotate_log" + start_cmd="accounting_start" stop_cmd="accounting_stop" +rotate_log_cmd="accounting_rotate_log" accounting_start() { local _dir - _dir=`dirname "$accounting_file"` - if [ ! -d `dirname "$_dir"` ]; then + _dir="${accounting_file%/*}" + if [ ! -d "$_dir" ]; then if ! mkdir -p "$_dir"; then - warn "Could not create $_dir." - return 1 + err 1 "Could not create $_dir." fi fi + if [ ! -e "$accounting_file" ]; then + echo -n "Creating accounting file ${accounting_file}" touch "$accounting_file" + echo '.' fi + chmod 644 "$accounting_file" - if [ ! -f ${accounting_file} ]; then - echo "Creating accounting file ${accounting_file}" - ( umask 022 ; > ${accounting_file} ) - fi - echo "Turning on accounting." + echo -n 'Turning on accounting' ${accounting_command} ${accounting_file} + echo '.' } accounting_stop() @@ -46,5 +50,26 @@ ${accounting_command} } +accounting_rotate_log() +{ + local _dir _file + + _dir="${accounting_file%/*}" + cd $_dir + + if checkyesno accounting_enable; then + _file=`mktemp newacct-XXXXX` + ${accounting_command} /var/account/${_file} + fi + + mv ${accounting_file} ${accounting_file}.0 + + if checkyesno accounting_enable; then + ln $_file ${accounting_file##*/} + ${accounting_command} ${accounting_file} + unlink $_file + fi +} + load_rc_config $name run_rc_command "$1" --------------080201010908080508080504--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4D63659E.6010305>