monarobase

Well-Known Member
PartnerNOC
Jan 26, 2010
529
21
68
France
cPanel Access Level
Root Administrator
I've just read through the hooks documentation.

Stats Functions

Seems that there is everything we could need to do this.

However when cPanel detects that it needs to delete a users log file, it seems that it renames the file then reloads apache.

What we would rearly need is a hook that would allow us to copy the renamed file (either just before the stats are run on it or just before the file is deleted.

It's better than nothing to be able to backup before the logs are deleted but there could still be a few lost entries while our backup is being run (we supposedly could minimise this by doing a hard copy of the file and running the backup on the hardcopy as a background process as to have only a few seconds of lost logs.
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
15
313
Houston, TX
cPanel Access Level
Root Administrator
Re: Ability to rotate apache domlogs after stats run (not delete) [Case 586

What we would rearly need is a hook that would allow us to copy the renamed file (either just before the stats are run on it or just before the file is deleted.
Are you referencing the .bkup file (copy of the domlog) here that is passed in as part of a hash/associative array in Stage:Pre?

Just remember to privilege escalate if necessary as that script is running as the cPanel user (not root) by default.
 

monarobase

Well-Known Member
PartnerNOC
Jan 26, 2010
529
21
68
France
cPanel Access Level
Root Administrator
Re: Ability to rotate apache domlogs after stats run (not delete) [Case 586

Are you referencing the .bkup file (copy of the domlog) here that is passed in as part of a hash/associative array in Stage:Pre?
Yes, would the post stage be able to access this file, or will this file already have been deleted at the time of the post stage ?

If it is accessable then I should have everything I need to do this, if not then I will have to wait and see if my feature request is implemented or not.
 

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
San Francisco, CA
cPanel Access Level
Root Administrator
I haven't gotten a chance to look at this directly but you can always write to STDERR (/usr/local/cpanel/logs/error_log) within your hooks. Try adding a simple hook for both the 'pre' and 'post' events that tells you whether or not the file exists (code not tested):


Code:
#!/usr/bin/perl

use JSON::Syck  ();

my $raw_data;
while (<STDIN>) {
    $raw_data .= $_;
}
my $hookdata = JSON::Syck::Load($raw_data);

my @logfiles = $hookdata->{'data'}->{'logfiledesc'};

foreach my $logfile (@logfiles){
   print STDERR "Log File: " . $logfile->{'logfile'} . "\n";
   -f $logfile->{'logfile'} ? print STDERR  "exists \n" : print STDERR  "does not exist \n";
}
 

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,212
15
313
Houston, TX
cPanel Access Level
Root Administrator
Re: Ability to rotate apache domlogs after stats run (not delete) [Case 586

Yes, would the post stage be able to access this file, or will this file already have been deleted at the time of the post stage ?

If it is accessable then I should have everything I need to do this, if not then I will have to wait and see if my feature request is implemented or not.
I had a conversation internally about this and the consensus is that yes, that file should still be accessible even in the post stage. However, we have not tested this scenario ourselves.