Got an email from my server about a failed Cron Job

October 30, 2015 10k views
LEMP Nginx Email Logging Ubuntu

I have a LEMP server running Ubuntu 14.04 LTS. (Nginx 1.8)

I got this email about a failed cron job.

Anyone have a solution?


Cron <root@domain> test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )


error: error running shared postrotate script for '/var/log/nginx/*.log '
run-parts: /etc/cron.daily/logrotate exited with return code 1

The only edit ive made lately was open /etc/logrotate.conf
I uncommented the following line so my log files will be compressed

# uncomment this if you want your log files compressed

Donno if that would have caused it?

2 Answers

@desiredpersona - Take a look at /etc/logrotate.d/nginx, does your file look like:

/var/log/nginx/*.log {
        rotate 52
        create 0640 www-data adm
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi \
                invoke-rc.d nginx rotate >/dev/null 2>&1

....if so, try swapping out:

invoke-rc.d nginx rotate >/dev/null 2>&1


nginx -s reload

If that doesn’t work, try swapping it out for:

service nginx rotate

I’ve seen reports that the invoke-rc.d..... line causes issues for others as well. It doesn’t seem to happen on Debian (I use Debian daily as a primary OS on most all personal, client and development deployments).

It would also be advisable to comment the compress line that you remove the comment from as, if your file contains the same command, compress is already defined as an option in the command, thus you shouldn’t need to define it elsewhere.

  • Thank you @jtittle
    I commented the compress line again in /etc/logrotate.conf

    I replaced ‘invoke-rc.d’ with 'service’ so the full line looks like this

    service nginx rotate >/dev/null 2>&1

check logrotation configurations are correct logrotate -f -v /etc/logrotate.d/nginxdf -h

Manually run the logrotationlogrotate -f -v /etc/logrotate.d/nginx to check if it’s working. (failed for me)

in some cases it logrotation may fail due to incorrect ownership of logs.

for me ownership of /var/log/nginx/domain.access.log was www-data:root.
we will need to change it using chown www-data:adm /var/log/nginx/*

running manually logrotate -f -v /etc/logrotate.d/nginx
and this worked and logs rotated successfully.

Have another answer? Share your knowledge.