Пример #1
0
function work()
{
    //return;
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/" . basename(__FILE__) . ".pid";
    $pidTime = "/etc/artica-postfix/" . basename(__FILE__) . ".time";
    if ($GLOBALS["VERBOSE"]) {
        echo "PidFile = {$pidfile}\n";
    }
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        system_admin_events("Other pid {$pid} running since {$timepid}mn", __FUNCTION__, __FILE__, __LINE__, "archive");
        die;
    }
    $TimeExec = $unix->file_time_min($pidTime);
    if ($TimeExec < 4) {
        return;
    }
    if (!is_dir("/var/spool/mail-rtt-backup")) {
        return;
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $pid = getmypid();
    file_put_contents($pidfile, $pid);
    $countDeFiles = 0;
    $t = time();
    if (!($handle = opendir("/var/spool/mail-rtt-backup"))) {
        @mkdir("/var/spool/mail-rtt-backup", 0755, true);
        die;
    }
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $targetFile = "/var/spool/mail-rtt-backup/{$filename}";
        if ($GLOBALS["VERBOSE"]) {
            echo "Processing {$targetFile}\n";
        }
        if (archive_process($targetFile)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "removing {$targetFile}\n";
            }
            @unlink($targetFile);
        }
        $countDeFiles++;
        if (system_is_overloaded(basename(__FILE__))) {
            $took = $unix->distanceOfTimeInWords($t, time());
            events("Fatal: Overloaded system {$GLOBALS["SYSTEM_INTERNAL_LOAD"]} after {$took} execution time processed {$countDeFiles} files ->  aborting task", __LINE__);
            die;
        }
    }
    ScanSize();
}
Пример #2
0
function ASSP_QUAR($baseDir)
{
    //""
    if (!is_dir($baseDir)) {
        return null;
    }
    $files = DirEML($baseDir);
    events("Processing " . count($files) . " files in {$baseDir}");
    while (list($num, $file) = each($files)) {
        if (archive_process("{$baseDir}/{$file}")) {
            WriteToSyslogMail("{$baseDir}/{$file} removed", __FILE__, false);
            @unlink("{$baseDir}/{$file}");
            events("processing {$baseDir}/{$file} success");
        } else {
            events("processing {$baseDir}/{$file} failed");
        }
    }
}