Logrotate error

Hi, I’m receving emails from remote server with this message. I’m not sure about its meaning (I am not familiar with cron and logrotate). Is it significant? How can I fix it? Thanks!

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

@aitor could you confirm that the version of Trellis you are working with includes the postrotate script update from roots/trellis#377 and that it appears in your server as well, e.g.,

ssh root@remote_ip 'less /etc/logrotate.d/wordpress-sites'

The current postrotate script should be just service nginx rotate

Yes, there it is:

Ansible managed: /Volumes/B/Documentos/trellis2/ansible/vendor/roles/logrotate/templates/logrotate.d.j2
modified on 2015-04-29 21:51:29 by aitor on 451

"/srv/www/**/logs/*.log" {
  weekly
  maxsize 50M
  missingok
  rotate 8
  compress
  delaycompress
  notifempty
  create 0640 web www-data
  sharedscripts
  postrotate
    service nginx rotate
  endscript
  prerotate
    if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
      run-parts /etc/logrotate.d/httpd-prerotate; \
    fi \

  endscript
  }

I’m having the same issue too, on occasion. Other times I’ll receive:

/etc/cron.daily/logrotate:
 * Re-opening nginx log files nginx
   ...done.

Checked my remote server and the postrotate script is service nginx rotate as @fullyint mentioned.

What version of Nginx are those of you getting the error using? There are some known bugs affecting some Nginx versions. Also, are the permissions for your logs folder/logs set correctly?

$ nginx -v
nginx version: nginx/1.9.11

/srv/www/contraindicaciones.net/logs$ ls -la
total 37068
drwxr-xr-x 2 web      www-data     4096 Apr 18 11:27 .
drwxr-xr-x 5 web      www-data     4096 Apr 20 07:40 ..
-rw-r----- 1 www-data www-data  8467729 Apr 21 04:30 access.log
-rw-r----- 1 www-data www-data 24741025 Apr 18 11:27 access.log.1
-rw-r----- 1 www-data www-data  2670858 Apr 10 11:51 access.log.2.gz
-rw-r----- 1 www-data www-data  1631499 Apr  3 11:46 access.log.3.gz
-rw-r--r-- 1 root     root       298772 Mar 27 11:31 access.log.4.gz
-rw-r----- 1 www-data www-data    36365 Apr 20 19:06 error.log
-rw-r----- 1 www-data www-data    60138 Apr 18 06:53 error.log.1
-rw-r----- 1 www-data www-data     2494 Apr 10 08:01 error.log.2.gz
-rw-r----- 1 www-data www-data     2814 Apr  3 07:44 error.log.3.gz
-rw-r--r-- 1 root     root          174 Mar 26 22:30 error.log.4.gz

Permissions look fine, you can manually fix the one log file (x.log.4.gz) if you need to - it’s an artifact of how nginx is running with roots/trellis. You can avoid it altogether in future installs by adding a script to be run manually or by ansible after the deploy.

One common reason for the error you’re seeing is that Upstart sucks. Quick check-- are both the Upstart and systemV initialization configs present (/etc/init/nginx and /etc/init.d/nginx)? You’re running on Ubuntu 14.04 (Trusty) right?

If they’re both there, stop ngninx, delete the Upstart one and restart. Should work fine. This was resolved I thought in later 1.8 versions and then for reasons I am not familiar with, it seems to have returned in nginx 1.9 mainlines.

Let me know if that does/doesn’t do the trick for your server.

See, the service manpage for more info.

The existence of an upstart job of the same name as a script in /etc/init.d
will cause the upstart job to take precedence over the init.d script.

4 Likes

Done! Thank you very much. I’m waiting for the next email from server to confirm the fix.

@alanc: after deleting the upstart script, nginx stopped auto-loading on startup. To get it to auto-load again I had to run:

sudo update-rc.d nginx defaults

Default install, @afonsoduarte? Curious.

This whole issue tangentially reminds me of a favorite old Ubuntu/Upstart quote:

…if you want to rely on anything upstart purports to bring to the table, get ready for dentist visit like fun time. - https://lwn.net/Articles/582585/

Maybe trellis could to move to CentOS? :wink:

Hi guys,

I’ve been receiving the same type of emails daily, for multiple Trellis installs.

For one install:

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

And for another one:

/etc/cron.daily/logrotate: 
* Re-opening nginx log files nginx 
...done. 

A local build is also sending this type of emails to Mailhog (first type listed above). Since it’s been appearing on multiple installs, i’d really love to find the cause of this. Any ideas?

Nginx version: 1.11.1

@jankups, you’re seeing this error even after checking/trying this and this? If so, could you post your postrotate script, plz?

@mathewc
The postrotate for first, with error “error running shared postrotate script”:

  postrotate
    service nginx rotate

For the second one with message “Re-opening nginx log files nginx” is the same.

Should I delete the nginx.conf file inside “/etc/init”?

Assuming you have the systemV initialization config, /etc/init.d/nginx, which you should have, then yes, you want to delete the Upstart one. Not to be a broken record on this, but check out the service manpage. Upstart is :poop: sometimes.

If you’re having issues after that with auto-loading nginx on startup run:
sudo update-rc.d nginx defaults
per this reply from @afonsoduarte.

Hope this solves your issue.

1 Like

Hi everyone,

I have the same error, every day:

/etc/cron.daily/logrotate:
Usage: /etc/init.d/nginx {start|stop|status|restart|reload|force-reload|upgrade|configtest|check-reload}
error: error running shared postrotate script for '"/srv/www/**/logs/*.log" '
run-parts: /etc/cron.daily/logrotate exited with return code 1

I tried to delete upstart job in /etc/init but there is nothing related to nginx or logrotate:

admin@vps:~$ ls /etc/init/
cgmanager.conf   network-interface.conf            php7.1-fpm.conf       udev.conf                    udevmonitor.conf
cgproxy.conf     network-interface-container.conf  ssh.conf              udev-fallback-graphics.conf  udevtrigger.conf
networking.conf  network-interface-security.conf   startpar-bridge.conf  udev-finish.conf

Can you help me?

Thanks!

Fix replacing: service nginx rotate
By:

if [ -f /var/run/nginx.pid ]; then
  kill -USR1 `cat /var/run/nginx.pid`
fi

In /etc/logrotate.d/wordpress-sites file, postrotate section.

Source: https://stackoverflow.com/a/39196140

Hi everyone, I’m getting this message every morning as well:

/etc/cron.daily/logrotate:

* Re-opening nginx log files nginx
  ...done.

None of above solutions worked for me, as that file /etc/init/nginx doesn’t exist but I managed to “fix” it by applying below patch to logrotate.xml

git diff
diff --git a/group_vars/all/logrotate.yml b/group_vars/all/logrotate.yml
index c6d2496..bbea7de 100644
--- a/group_vars/all/logrotate.yml
+++ b/group_vars/all/logrotate.yml
@@ -17,4 +17,4 @@ logrotate_scripts:
         if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
               run-parts /etc/logrotate.d/httpd-prerotate; \
             fi \
-      postrotate: service nginx rotate
+      postrotate: service nginx rotate 2>&1 >/dev/null

I know it could potentially be hiding other messages, but theoretically not errors, and I rather this than getting an annoying email every day :slight_smile:
Hope it helps!