[ISPConfig3] Manueller Aufruf von server/cron_daily.php

mattula

Member
Ist es ok server/cron_daily.php manuell per

php -q server/cron_daily.php


aufzurufen, um bspw. gleich das Ergebnis einer Umstellung von webalizer auf awstats anschauen zu koennen?


Gruss,
Matthias
 

Till

Administrator
Du solltest immer das jeweilige .sh Script aufrufen und nicht direkt das .php script, denn das .sh script setzt die path Variable so wie es ISPConfig benötigt.

Wenn Du also das Script testen willst, dann ist der befehl:

/usr/local/ispconfig/server/cron_daily.sh

Das kann aber ein paar Nebenwirkungen haben, denn das Script ist dafür ausgelegt dass es genau einmal pro Tag aufgerufen wird, es nimmt also keine Überprüfungen vor ob es am selben Tage bereits gelaufen ist. Die Nebenwirkungen sind z.B. doppelte Backups.
 

mattula

Member
Wenn Du also das Script testen willst, dann ist der befehl:

/usr/local/ispconfig/server/cron_daily.sh

Das kann aber ein paar Nebenwirkungen haben, denn das Script ist dafür ausgelegt dass es genau einmal pro Tag aufgerufen wird, es nimmt also keine Überprüfungen vor ob es am selben Tage bereits gelaufen ist. Die Nebenwirkungen sind z.B. doppelte Backups.

OK, ist denn eine Moeglichkeit vorgesehen, nur die Webalizer/Awstats Statistiken zu aktualisieren? Am liebsten taet ich die Statistiken wenigstens stuendlich aktualisieren wollen.

Ich koennte mir natuerlich aus der server/cron_daily.php die entsprechenden Schnipsel fuer die Statsitik Updates rausziehen, als cron_hourly_stats.php speichern und daraus einen eigenen Cron Job basteln. :)

Btw, wie werden eigentlich die naechtlichen Crons getriggert? Es gibt doch eigentlich nur den einen minuetlichen root Cron Job, oder? Macht der basierend auf bestimmten Zeiten die Zusatz Tasks quasi mit?

Gruss,
Matthias
 

nowayback

Well-Known Member
Irgendwo hab ich mal folgendes gefunden:

runstats.php:
Code:
<?php

/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


require('/usr/local/ispconfig/server/lib/config.inc.php');
require('/usr/local/ispconfig/server/lib/app.inc.php');
set_time_limit(0);

// make sure server_id is always an int
$conf['server_id'] = intval($conf['server_id']);
// Load required base-classes
$app->uses('ini_parser,file,services,getconf');

#######################################################################################################
// Create awstats statistics
#######################################################################################################

$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE stats_type = 'awstats' AND server_id = ".$conf['server_id'];
$records = $app->db->queryAllRecords($sql);
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
foreach($records as $rec) {
        $logfile = escapeshellcmd($rec['document_root'].'/log/access.log');
        $domain = escapeshellcmd($rec['domain']);
        $statsdir = escapeshellcmd($rec['document_root'].'/web/stats');
        $awstats_pl = $web_config['awstats_pl'];
        $awstats_buildstaticpages_pl = $web_config['awstats_buildstaticpages_pl'];
        $awstats_conf_dir = $web_config['awstats_conf_dir'];
        $awstats_website_conf_file = $web_config['awstats_conf_dir'].'/awstats.'.$domain.'.conf';
        if(is_file($awstats_website_conf_file)) unlink($awstats_website_conf_file);
        if(!is_file($awstats_website_conf_file)) {
                $awstats_conf_file_content = 'Include "'.$awstats_conf_dir.'/awstats.conf"
                LogFile="/var/log/ispconfig/httpd/'.$domain.'/access.log"
                SiteDomain="'.$domain.'"
                HostAliases="www.'.$domain.' localhost 127.0.0.1"';
                file_put_contents($awstats_website_conf_file,$awstats_conf_file_content);
        }
 if(!@is_dir($statsdir)) mkdir($statsdir);

        // awstats_buildstaticpages.pl -update -config=mydomain.com -lang=de -dir=/var/www/domain.com/web/stats -awstatsprog=/path/to/awstats.pl
        $command = "$awstats_buildstaticpages_pl -update -config='$domain' -lang=de -dir='$statsdir' -awstatsprog='$awstats_pl'";

        if($awstats_pl != '' && $awstats_buildstaticpages_pl != '' && fileowner($awstats_pl) == 0 && fileowner($awstats_buildstaticpages_pl) == 0) {
                exec($command);
                rename($rec['document_root'].'/web/stats/awstats.'.$domain.'.html',$rec['document_root'].'/web/stats/index.html');
                $app->log('Created awstats statistics with command: '.$command,LOGLEVEL_DEBUG);
        } else {
                $app->log("No awstats statistics created. Either $awstats_pl or $awstats_buildstaticpages_pl is not owned by root user.",LOGLEVEL_WARN);
        }

}


die("finished.\n");
?>

und
runstats.sh:
Code:
#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin
/usr/bin/php /root/run_awstats.php

Quelle kann ich dir leider nicht mehr nennen, da ich diese einfach nicht mehr finden kann. Aber evtl. hilft es dir ja.

Grüße
nwb
 

mattula

Member
Irgendwo hab ich mal folgendes gefunden:

runstats.php:
und
runstats.sh:

Danke, das scheint mir auf den ersten Blick das was ich meinte mit "die entsprechenden Schnipsel fuer die Statistik Updates rausziehen und daraus einen eigenen Cron Job basteln". Und laut Copyright war es wohl Till himself, der diese Idee schon umgesetzt hatte. :)

Im Gegensatz zum cron_daily.php wird hier z.B. auch das aktuelle access.log statt dem von gestern verwendet. Was eindeutig im Sinn der Sache ist. ;)

@Till
Das Script stammt ja offensichtlich von dir - hat das so noch Gueltigkeit?

Gruss,
Matthias
 

Till

Administrator
Das Script ist nicht von mir, ich denke mal da hat jemand nur mein Copyright aus dem crob_daily.php drin gelassen.

Wenn Du auf nummer sicher gehen willst, dann bau Dir leiber ein neues Script aus der cron_daily.php zusammen indem Du alles zwischen den ersten include zeilen und dem awstats Bereich löschst und dann alles nach dem awstats löschen und ggf.den Pfad des access log anpassen.
 

Werbung

Top