Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am using Piwik Analytics on a site that doesn't run any javascript and I would prefer to have data created from the access logs instead of from the image tracker - results from the logs are actually better because they can include static file downloads.

This is a LEMP server with Ubuntu 12.04 and nginx 1.4.5.

The python script is located at /var/www/ and would need to run with several options. The access log is located at /var/www/

The relevant portion of /etc/logrotate.d/nginx contains:

/var/www/*/logs/*.log {
   rotate 36500
   create 0640 www-data adm
       if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
           run-parts /etc/logrotate.d/httpd-prerotate; \
       fi; \
                [ -s /run/ ] && kill -USR1 `cat /run/`

I don't know how to integrate a python script such that it will run at the end of this (after the rotations have completed).


An additional issue I didn't consider initially is that this script only needs to run for one domain - the rest of the domains on the server do not require the script. The file above I created so that it would automatically rotate logs for all domains added to the server without my having to edit /etc/logrotate.d/nginx.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can put the command you want to be executed between the postrotate and endscript lines (make sure to keep the line already there):

      [ -s /run/ ] && kill -USR1 `cat /run/`
      /usr/bin/python /var/www/ somearguments
share|improve this answer
That's so... simple! Thanks! Of course, I just reread my question and realized I have one outstanding issue I didn't address initially and I just edited the question to reflect this. Is is possible to only apply the solution such that the script only runs for one domain? –  Paul Mar 1 '14 at 23:08
That totally depends on how the script works (which I'm not familiar with). The script is executed after all logs are rotated, what exactly it does and with what logs is entirely up to the script. –  Teun Vink Mar 1 '14 at 23:12
The script just parses data from the access log and migrates it into the Piwik database. If it ran for every site, then the data could not be used for analysis. It could also work to tell logrotate not to run on a specific location and have a separate entry for that location, or I suppose I could just stop being lazy and make a separate entry for each domain. –  Paul Mar 1 '14 at 23:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.