From owner-freebsd-questions@FreeBSD.ORG Thu Oct 2 10:17:30 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F2A77106568E for ; Thu, 2 Oct 2008 10:17:30 +0000 (UTC) (envelope-from frank@esperance-linux.co.uk) Received: from mailout.zetnet.co.uk (mailout.zetnet.co.uk [194.247.47.231]) by mx1.freebsd.org (Postfix) with ESMTP id 83B568FC21 for ; Thu, 2 Oct 2008 10:17:30 +0000 (UTC) (envelope-from frank@esperance-linux.co.uk) Received: from irwell.zetnet.co.uk ([194.247.47.48] helo=zetnet.co.uk) by mailout.zetnet.co.uk with esmtp (Exim 4.63) (envelope-from ) id 1KlLFM-0006MH-NH; Thu, 02 Oct 2008 11:17:24 +0100 Received: from melon.esperance-linux.co.uk (54-144.adsl.zetnet.co.uk [194.247.54.144]) by zetnet.co.uk (8.14.1/8.14.1/Debian-9) with ESMTP id m92AHNMm022781; Thu, 2 Oct 2008 11:17:23 +0100 Received: by melon.esperance-linux.co.uk (Postfix, from userid 1001) id D8968FCA4AD; Thu, 2 Oct 2008 11:17:17 +0100 (BST) Date: Thu, 2 Oct 2008 11:17:17 +0100 From: Frank Shute To: Grant Peel Message-ID: <20081002101717.GA10650@melon.esperance-linux.co.uk> Mail-Followup-To: Grant Peel , freebsd-questions@freebsd.org References: <668A2B1DDBEC40BCAC6A82589B5D1159@GRANT> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <668A2B1DDBEC40BCAC6A82589B5D1159@GRANT> User-Agent: Mutt/1.4.2.3i X-Face: *}~{PHnDTzvXPe'wl_-f%!@+r5; VLhb':*DsX%wEOPg\fDrXWQJf|2\,92"DdS%63t*BHDyQ|OWo@Gfjcd72eaN!4%NE{0]p)ihQ1MyFNtWL X-Operating-System: FreeBSD 6.3-RELEASE-p2 i386 X-Organisation: 'http://www.shute.org.uk/' X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (zetnet.co.uk [194.247.46.1]); Thu, 02 Oct 2008 11:17:23 +0100 (BST) Cc: freebsd-questions@freebsd.org Subject: Re: Logrotate X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Frank Shute List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Oct 2008 10:17:31 -0000 On Wed, Oct 01, 2008 at 07:52:48PM -0400, Grant Peel wrote: > > Hi all, > > I have recently started using logrotate to rotate all the logs in the users > home directories. These are all apache logs files. > > /home/domain.com/logsaccess_log > /home/domain.com/logsaccess_log.0.gz > /home/domain.com/logsaccess_log.1.gz > /home/domain.com/logsaccess_log.2.gz > > I have a problem though. Some of my domains have softlinks pointing to > them, this causes the logs to be rotated 2 or more times (i.e. 1 time for > the 'real' directory, and 1 time each for each softlink pointing to them). > > Example > > /home/domain.com/logs/ > domain2.com -> domain.com > domain3.com -> domain.com > > will result in the 'access_log' being rotated 3 times in one run, causing > my log dirs to look like this: > > -rw-r--r-- 1 root holt 160 Oct 1 05:44 access_log > -rw-r--r-- 1 root holt 446 Oct 1 05:44 error_log > -rw-r--r-- 1 root holt 20 Oct 1 03:46 access_log.1.gz > -rw-r--r-- 1 root holt 20 Oct 1 03:46 access_log.2.gz > -rw-r--r-- 1 root holt 20 Oct 1 03:46 access_log.3.gz > -rw-r--r-- 1 root holt 20 Oct 1 03:46 access_log.4.gz > -rw-r--r-- 1 root holt 20 Oct 1 03:46 access_log.5.gz > -rw-r--r-- 1 root holt 20 Oct 1 03:46 access_log.6.gz > -rw-r--r-- 1 root holt 224 Oct 1 03:46 access_log.7.gz > -rw-r--r-- 1 root holt 20 Sep 30 03:46 access_log.8.gz > -rw-r--r-- 1 root holt 20 Sep 30 03:46 access_log.9.gz > > Here is this appropriate part of my logrotate.conf > > # logrotate.conf > > compress > > ... > > /home/*/logs/access_log { > missingok > rotate 14 > daily > create 644 root > sharedscripts > postrotate > /usr/local/sbin/apachectl restart > endscript > } > > # End of logrotate.conf > > > Question, is there a way to stop this from happening? > > -Grant > Aswell as doing what Jeremy Chadwick mentioned, you might want to use newsyslog(8) to rotate your logs. It's got a couple of advantages that I know of: it's part of the base system and it gracefully sends Apache a signal (SIGUSR1) to stop it writing to the logfile before it rotates it. You want something like the following in newsyslog.conf(5): /var/log/httpd-access.log 644 5 200 * B /var/run/httpd.pid 30 Obviously, adjust the parameters to suit your needs. You want the 30 at the end. All explained in the manpage. Regards, -- Frank Contact info: http://www.shute.org.uk/misc/contact.html