Run scripts before domlog rotates
I'm running a CentOS 6.9 VPS with cpanel/whm. Currently, my apache2 domlogs rotate daily. I need to run scripts that parse a domain log before it rotates.
I tried adding:
prerotate
/usr/local/bin/dstats > /dev/null 2>/dev/null || true
/usr/local/bin/dreport > /dev/null 2>/dev/null || true
endscript
to logrotate.d/httpd, but the scripts didn't appear to run. Investigating further, I see that logrotate.conf is set to rotate logs weekly.
What do I need to do to run these scripts before the domlog rotates?
-
Still no joy with this issue. As far as I can tell, the logrotate.conf does not control the daily rotation of the apache2/domlogs. Google has been zero help in solving this. Very frustrating, after hours of research. 0 -
Hello, The following option is available under the "Stats and Logs" tab in "WHM >> Tweak Settings": "Delete each domain"s access logs after statistics are gathered" Per it's description: This setting will force the system to delete all access logs after each run. Thus, you'd need to disable this option and rotate the Apache domlogs on your own, or setup a hook that runs your custom script "pre" log processing: Guide to Standardized Hooks - Software Development Kit - cPanel Documentation Guide to Standardized Hooks - Stats Functions - Software Development Kit - cPanel Documentation Thank you. 0 -
Thank you. 0 -
I tried the code below, it appeared to register properly: System: Stats: weight: 100 hook: MyStats::runscripts exectype: module stage: pre id: KrW3DbP2pUlaz99VVnx7KWNe However, calling the script (sub: runscripts) doesn't work. The script being called executes w/o issues manually. #!/usr/bin/perl # Package this module. package MyStats; # Return errors if Perl experiences problems. use strict; use warnings; # Use cPanel's error logging module. use Cpanel::Logger; # Instantiate the cPanel logging object. my $logger = Cpanel::Logger->new(); # Embed hook attributes alongside the action code. sub describe { my $hooks = [ { 'category' => 'System', 'event' => 'Stats', 'stage' => 'pre', 'hook' => 'MyStats::runscripts', 'exectype' => 'module', } ]; return $hooks; } sub runscripts { system("/bin/bash /usr/local/bin/dstats"); }; 0 -
Hello, If you already have a script that works when you run it manually, you can simply add it to the hooks system using a command like this rather than setting up a separate custom script: /usr/local/cpanel/bin/manage_hooks add script /var/cpanel/myapp/myscript.sh --manual --category System --event Stats --stage pre
Thank you.0 -
That seems simple enough, thanks! How do you delete a hook entered in this manner? I tried: bin/manage_hooks del script /usr/local/bin/myscript, but no joy. 0 -
How do you delete a hook entered in this manner? I tried: bin/manage_hooks del script /usr/local/bin/myscript, but no joy.
You'd use a command like this:/usr/local/cpanel/bin/manage_hooks delete script /var/cpanel/myapp/myscript.sh --manual --category System --event Stats --stage pre
Or, simply use "WHM Home " Development " Manage Hooks". We document this at: Guide to Standardized Hooks - The manage_hooks Utility - Software Development Kit - cPanel Documentation Thank you.0
Please sign in to leave a comment.
Comments
7 comments