The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using stats:: standard hook

Discussion in 'cPanel Developers' started by monarobase, Apr 4, 2012.

  1. monarobase

    monarobase Well-Known Member

    Joined:
    Jan 26, 2010
    Messages:
    503
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    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.
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    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?

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

    monarobase Well-Known Member

    Joined:
    Jan 26, 2010
    Messages:
    503
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    France
    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.
     
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I've moved our conversation over to the Integration forum where it can receive better attention from those who know these things :).
     
  5. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    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";
    }
    
     
  6. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Re: Ability to rotate apache domlogs after stats run (not delete) [Case 586

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

Share This Page