Take the 2-minute tour ×
Server Fault is a question and answer site for professional 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/example1.com/public/piwik/misc/log-analytics/import-logs.py and would need to run with several options. The access log is located at /var/www/example2.com/logs/access.log.1.

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

/var/www/*/logs/*.log {
   daily
   missingok
   rotate 36500
   compress
   delaycompress
   notifempty
   create 0640 www-data adm
   sharedscripts
   prerotate
       if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
           run-parts /etc/logrotate.d/httpd-prerotate; \
       fi; \
   endscript
   postrotate
                [ -s /run/nginx.pid ] && kill -USR1 `cat /run/nginx.pid`
        endscript
}

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

Edit:

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
add comment

1 Answer 1

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

   postrotate
      [ -s /run/nginx.pid ] && kill -USR1 `cat /run/nginx.pid`
      /usr/bin/python /var/www/example1.com/public/piwik/misc/log-analytics/import-logs.py somearguments
   endscript
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 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 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 at 23:18
add comment

Your Answer

 
discard

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.