Got an email from my server about a failed Cron Job

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?


This seems to be a bug in the postrotate script in /etc/logrotate.d/nginx as reported here. Try:

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

@franklinkim Thanks Kevin. That solved the issue

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

@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.

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.