From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 22 07:28:38 2011 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0E2761065673 for ; Tue, 22 Feb 2011 07:28:38 +0000 (UTC) (envelope-from dougb@dougbarton.us) Received: from mail2.fluidhosting.com (mx22.fluidhosting.com [204.14.89.5]) by mx1.freebsd.org (Postfix) with ESMTP id 9FB308FC12 for ; Tue, 22 Feb 2011 07:28:37 +0000 (UTC) Received: (qmail 699 invoked by uid 399); 22 Feb 2011 07:28:32 -0000 Received: from router.ka9q.net (HELO doug-optiplex.ka9q.net) (dougb@dougbarton.us@75.60.237.91) by mail2.fluidhosting.com with ESMTPAM; 22 Feb 2011 07:28:32 -0000 X-Originating-IP: 75.60.237.91 X-Sender: dougb@dougbarton.us Message-ID: <4D63659E.6010305@dougbarton.us> Date: Mon, 21 Feb 2011 23:28:30 -0800 From: Doug Barton Organization: http://SupersetSolutions.com/ User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.13) Gecko/20110129 Thunderbird/3.1.7 MIME-Version: 1.0 To: freebsd-hackers@FreeBSD.org References: <4D6323D9.5090500@dougbarton.us> In-Reply-To: <4D6323D9.5090500@dougbarton.us> X-Enigmail-Version: 1.1.2 OpenPGP: id=1A1ABC84 Content-Type: multipart/mixed; boundary="------------080201010908080508080504" X-Mailman-Approved-At: Tue, 22 Feb 2011 12:46:23 +0000 Cc: Subject: Re: Problem with etc/periodic/daily/310.accounting X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Feb 2011 07:28:38 -0000 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--