0

I have a log file a service of mine makes that has the filename "Feed1 - 1.stat". logrotate refuses to rotate this file, but only when run via cron. Running logrotate via the shell will rotate the file correctly. Changing the config and and log file to not have a space will also result in the file rotating correctly.

Heres the relevant part of the script script:

"/opt/myservice/statistics/continuous/Feed1 - 1.stat"
{
  rotate 60
  daily
  missingok
  notifempty
  compress
  delaycompress
  postrotate
    /usr/bin/killall -HUP myservice
  endscript
}

And here's the cron entry that kicks off logrotate (Ubuntu default):

#!/bin/sh

# Clean non existent log file entries from status file
cd /var/lib/logrotate
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
    [ -e "$logfile" ] && echo "\"$logfile\" $date"
done >> status.clean
mv status.clean status

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf

I suspect something perhaps related to enviroment variables? I can see the cron enviroment is rather sparse, but don't know how to debug this from here on.

Any ideas? Thanks :-)


Ubuntu 11.04 Natty 64 bit

2.6.38-8-server

logrotate 3.7.8-6ubuntu3.1


Edits:

  • Rewrote question as I found out it doesn't have to do with the wildcard matching
Frederik
  • 153
  • 8

2 Answers2

1

The Ubuntu logrotate cron script is broken and strips out the double quotation marks from the status file. It then checks if the file exists, which it doesn't because the quotes are gone, and removes the line. Then logrotate re-adds the line on execution, but as it just added it, doesn't rotate. Ad infinitum.

I'll file a bug on Launchpad.

Edit: And heres the bug report: https://bugs.launchpad.net/ubuntu/+source/logrotate/+bug/932225

Frederik
  • 153
  • 8
0

It sounds like problem with permissions. did you check that ? {I suppose that in console you execute lograte as root }

Except for that, just to mention that you can always rotate it by size, not only by time.

Nikolaidis Fotis
  • 2,032
  • 11
  • 13
  • Nikolaidis, I just looked it up: cron runs as root, and kicks of logrotate running as root too, so I don't think it's that – Frederik Feb 13 '12 at 16:31
  • Hmmmm. do you have cron's logs ? they may give a hint – Nikolaidis Fotis Feb 13 '12 at 17:11
  • Just noticed ... third and fourth are under /opt, while first and second under /var/log .... So ... could you recheck permissions in /opt ? {As root, try to append something in "/opt/myservice/statistics/continuous/*.stat" } – Nikolaidis Fotis Feb 13 '12 at 17:13
  • Nikolaidis, I can happily edit those files as root. I can't see much in /var/log about cron - a couple messages in syslog, but thats it. I've setup the logrotate cron script to run in verbose mode and log its output, so maybe we'll see tomorrow. Thanks! – Frederik Feb 13 '12 at 18:08