logrotate at midnight

Logrotate and Crons are great but they pose a problem. Have a look at my logs from 2015-09-17:

[root@abpmiddleware tmp]# head ronin.log-20150918
[2015-09-17 03:24:20] [e39947fb] [ DEBUG ] [request,headers] {"api-time":"2015-09-17 03:24:20","api-hash":"yyy","api-key":"xx"}
[2015-09-17 03:24:20] [e39947fb] [ DEBUG ] [ipcheck] authorizing request by ip address ...
[2015-09-17 03:24:20] [e39947fb] [ DEBUG ] [crm] calling crm http://****/cservice.svc/customer/login ...
[2015-09-17 03:24:21] [e39947fb] [ DEBUG ] [response] outgoing response {"headers":{},"body":"{"code":0,"error":null,"accountlst":....}}

See? It starts at 3:24 and ends at 3:17:

[root@abpmiddleware tmp]# tail ronin.log-20150918
[2015-09-18 03:17:38] [5211b2ad] [ DEBUG ] [hnserver] got collectedBalanceStat request
[2015-09-18 03:17:38] [5211b2ad] [ DEBUG ] [hnserver] Validating user inputs
[2015-09-18 03:17:38] [5211b2ad] [ DEBUG ] [hnserver] validation user inputs result: true
[2015-09-18 03:17:38] [5211b2ad] [ DEBUG ] [hnserver] calling webservice...
[2015-09-18 03:17:38] [3b46eba2] [ DEBUG ] [crm] got crm response
[2015-09-18 03:17:38] [3b46eba2] [ DEBUG ] [response] outgoing response {"headers":{},"body":"{"code":0,"error":null,"ticketlog":...}}
[2015-09-18 03:17:38] [5211b2ad] [ DEBUG ] [hnserver] got webservice response

The problem is the fact that cron does not start the daily tasks at 00:00 and just makes sure that is will be run once a day.

Solution? Move the logrotate somewhere else and create a crontab to run it every day at 0:0.


mv /etc/cron.daily/logrotate /usr/sbin/logrotate.cron
crontab -e
# add this line:
# 59 23 * * * /usr/sbin/logrotate.cron

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s