From owner-freebsd-questions@FreeBSD.ORG Thu Oct 2 06:26:55 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 08A721065693 for ; Thu, 2 Oct 2008 06:26:55 +0000 (UTC) (envelope-from jdc@koitsu.dyndns.org) Received: from QMTA04.emeryville.ca.mail.comcast.net (qmta04.emeryville.ca.mail.comcast.net [76.96.30.40]) by mx1.freebsd.org (Postfix) with ESMTP id E1D798FC23 for ; Thu, 2 Oct 2008 06:26:54 +0000 (UTC) (envelope-from jdc@koitsu.dyndns.org) Received: from OMTA05.emeryville.ca.mail.comcast.net ([76.96.30.43]) by QMTA04.emeryville.ca.mail.comcast.net with comcast id MiCe1a0030vp7WLA4iSurX; Thu, 02 Oct 2008 06:26:54 +0000 Received: from koitsu.dyndns.org ([67.180.253.227]) by OMTA05.emeryville.ca.mail.comcast.net with comcast id MiSt1a0024v8bD78RiStZv; Thu, 02 Oct 2008 06:26:54 +0000 X-Authority-Analysis: v=1.0 c=1 a=QycZ5dHgAAAA:8 a=0b_mWL7R4F_OpD4DzywA:9 a=zUzrgBb-FIHA2t8nQLlOA8XI6mcA:4 a=iYmc3lcGIqYA:10 a=18V52DnGmcoA:10 a=pPeV6em2N6YA:10 a=xNMxlJ1DscwA:10 a=EoioJ0NPDVgA:10 a=LY0hPdMaydYA:10 Received: by icarus.home.lan (Postfix, from userid 1000) id 00BE8C9432; Wed, 1 Oct 2008 23:26:52 -0700 (PDT) Date: Wed, 1 Oct 2008 23:26:52 -0700 From: Jeremy Chadwick To: Grant Peel Message-ID: <20081002062652.GA40660@icarus.home.lan> 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.5.18 (2008-05-17) Cc: freebsd-questions@freebsd.org Subject: Re: Logrotate X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Oct 2008 06:26:55 -0000 On Wed, Oct 01, 2008 at 07:52:48PM -0400, Grant Peel wrote: > 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? The problem is that you're using a wildcard in your log list: /home/*/logs/access_log is going to expand to: /home/domain.com/logs/access_log /home/domain2.com/logs/access_log /home/domain3.com/logs/access_log /home/...anythingelse.../logs/access_log So the software will do exactly what you asked for. What we use on our production webservers: LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined CustomLog "/var/log/httpd-access.log" combined This puts the VirtualHost name being accessed as the first field in the logfile. Every night, via a cronjob, we split the file up per VirtualHost using a script that comes with Apache called split-logfile. E.g.: cd where_you_want_the_logs /usr/local/sbin/split-logfile < /var/log/httpd-access.log This will make a separate logfile per virtual host name, and you can do whatever you want from there on out. There's a performance advantage here as well: one logfile means only one file descriptor open, which is Good(tm). Multiple logfiles opened under Apache does not scale well. -- | Jeremy Chadwick jdc at parodius.com | | Parodius Networking http://www.parodius.com/ | | UNIX Systems Administrator Mountain View, CA, USA | | Making life hard for others since 1977. PGP: 4BD6C0CB |