Пример #1
0
function CleanLogs()
{
    cleanTmplogs();
    CleanDirLogs('/var/log');
    CleanDirLogs('/opt/artica/tmp');
    CleanDirLogs('/etc/artica-postfix/pids');
    CleanDirLogs('/opt/artica/install');
    phplogs();
    CleanClamav();
    $size = str_replace(" ", " ", FormatBytes($GLOBALS["DELETED_SIZE"]));
    echo "{$size} cleaned :  {$GLOBALS["DELETED_FILES"]} files\n";
    if ($GLOBALS["DELETED_SIZE"] > 500) {
        send_email_events("{$size} logs files cleaned", "{$GLOBALS["DELETED_FILES"]} files cleaned for {$size} free disk space", "logs_cleaning");
    }
}
Пример #2
0
function CleanLogs($aspid = false)
{
    $timefile = "/etc/artica-postfix/pids/exec.clean.logs.php.CleanLogs.time";
    if (!$aspid) {
        $maxtime = 480;
        $unix = new unix();
        $pidpath = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidpath);
        if ($unix->process_exists($pid)) {
            $unix->events(basename(__FILE__) . ":: " . __FUNCTION__ . " Already process {$pid} running.. Aborting");
            return;
        }
        @file_put_contents($pidpath, getmypid());
        $timeOfFile = $unix->file_time_min($timefile);
        $unix->events("CleanLogs():: Time {$timeOfFile}/{$maxtime}");
        if ($timeOfFile < $maxtime) {
            $unix->events("CleanLogs():: Aborting");
            return;
        }
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    cleanRoot();
    maillog();
    MakeSpace();
    cleanRoot();
    CheckSingle_logfile("/var/log/php.log", 102400);
    CheckSingle_logfile("/opt/squidsql/error.log", 51200);
    CheckSingle_logfile("/var/log/atop.log", 1024);
    CheckSingle_logfile("/var/log/php5-fpm.log", 1024);
    CheckSingle_logfile("/var/log/artica-squid-stats.log", 10240);
    CheckSingle_logfile("/var/log/atop.log", 10240);
    CheckSingle_logfile("/var/log/apache2/access-common.log", 204800);
    wrong_number();
    Clean_tmp_path();
    CleanOldInstall();
    LogRotateTimeAndSize("/var/log/samba");
    if (system_is_overloaded(dirname(__FILE__))) {
        $unix->send_email_events("logs cleaner task aborting, system is overloaded", "stopped after CleanOldInstall()\nWill restart in next cycle...", "system");
        return;
    }
    CleanBindLogs();
    if (system_is_overloaded(dirname(__FILE__))) {
        $unix->send_email_events("logs cleaner task aborting, system is overloaded", "stopped after CleanBindLogs()\nWill restart in next cycle...", "system");
        return;
    }
    $unix->events(basename(__FILE__) . ":: " . __FUNCTION__ . " Cleaning Clamav bases");
    CleanClamav();
    if (system_is_overloaded(dirname(__FILE__))) {
        $unix->send_email_events("logs cleaner task aborting, system is overloaded", "stopped after CleanClamav()\nWill restart in next cycle...", "system");
        return;
    }
    $size = str_replace("&nbsp;", " ", FormatBytes($GLOBALS["DELETED_SIZE"]));
    echo "{$size} cleaned :  {$GLOBALS["DELETED_FILES"]} files\n";
    if ($GLOBALS["DELETED_SIZE"] > 500) {
        send_email_events("{$size} logs files cleaned", "{$GLOBALS["DELETED_FILES"]} files cleaned for {$size} free disk space:\n\n\t\t" . @implode("\n", $GLOBALS["UNLINKED"]), "logs_cleaning");
    }
    $GLOBALS["DELETED_SIZE"] = 0;
    $GLOBALS["DELETED_FILES"] = 0;
    $unix->events(basename(__FILE__) . ":: " . __FUNCTION__ . " initalize");
    init();
    $unix->events(basename(__FILE__) . ":: " . __FUNCTION__ . " cleanTmplogs()");
    cleanTmplogs();
    if (system_is_overloaded(dirname(__FILE__))) {
        $unix->send_email_events("logs cleaner task aborting, system is overloaded", "stopped after cleanTmplogs()\nWill restart in next cycle...", "system");
        return;
    }
    $unix->events(basename(__FILE__) . ":: " . __FUNCTION__ . " Cleaning /opt/artica/tmp");
    CleanDirLogs('/opt/artica/tmp');
    if (system_is_overloaded(dirname(__FILE__))) {
        $unix->send_email_events("logs cleaner task aborting, system is overloaded", "stopped after CleanDirLogs(/opt/artica/tmp)\nWill restart in next cycle...", "system");
        return;
    }
    $unix->events(basename(__FILE__) . ":: " . __FUNCTION__ . " Cleaning /opt/artica/install");
    CleanDirLogs('/opt/artica/install');
    if (system_is_overloaded(dirname(__FILE__))) {
        $unix->send_email_events("logs cleaner task aborting, system is overloaded", "stopped after CleanDirLogs(/opt/artica/install)\nWill restart in next cycle...", "system");
        return;
    }
    $unix->events(basename(__FILE__) . ":: " . __FUNCTION__ . " Cleaning phplogs");
    phplogs();
    if (system_is_overloaded(dirname(__FILE__))) {
        $unix->send_email_events("logs cleaner task aborting, system is overloaded", "stopped after phplogs()\nWill restart in next cycle...", "system");
        return;
    }
    $unix->events(basename(__FILE__) . ":: " . __FUNCTION__ . " Cleaning /opt/openemm/tomcat/logs");
    CleanDirLogs('/opt/openemm/tomcat/logs');
    $unix->events(basename(__FILE__) . ":: " . __FUNCTION__ . " Cleaning PHP Sessions");
    sessions_clean();
    $unix->events(basename(__FILE__) . ":: " . __FUNCTION__ . " Cleaning old install sources packages");
    $size = str_replace("&nbsp;", " ", FormatBytes($GLOBALS["DELETED_SIZE"]));
    echo "{$size} cleaned :  {$GLOBALS["DELETED_FILES"]} files\n";
    if ($GLOBALS["DELETED_SIZE"] > 500) {
        send_email_events("{$size} logs files cleaned", "{$GLOBALS["DELETED_FILES"]} files cleaned for {$size} free disk space:\n\n\t\t" . @implode("\n", $GLOBALS["UNLINKED"]), "logs_cleaning");
    }
}
Пример #3
0
function CleanLogs(){
	maillog();
	$maxtime=480;
	$unix=new unix();
	$pidpath="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
	$oldpid=@file_get_contents($pidpath);
	if($unix->process_exists($oldpid)){
		$unix->events(basename(__FILE__).":: ".__FUNCTION__." Already process $oldpid running.. Aborting");
		return;
	}
	
	@file_put_contents($pidpath,getmypid());
	
	$timefile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".time";
	$timeOfFile=$unix->file_time_min($timefile);
	$unix->events("CleanLogs():: Time $timeOfFile/$maxtime");
	if($timeOfFile<$maxtime){
		$unix->events("CleanLogs():: Aborting");
		return;
	}
	@unlink($timeOfFile);
	@file_put_contents($timeOfFile,"#");
	
	CleanOldInstall();
	CleanBindLogs();
	$unix->events(basename(__FILE__).":: ".__FUNCTION__." Cleaning Clamav bases");
	CleanClamav();
	$size=str_replace("&nbsp;"," ",FormatBytes($GLOBALS["DELETED_SIZE"]));
	echo "$size cleaned :  {$GLOBALS["DELETED_FILES"]} files\n";
	if($GLOBALS["DELETED_SIZE"]>500){
		send_email_events("$size logs files cleaned",
		"{$GLOBALS["DELETED_FILES"]} files cleaned for $size free disk space:\n
		".@implode("\n",$GLOBALS["UNLINKED"]),"logs_cleaning");
	}	
	$GLOBALS["DELETED_SIZE"]=0;
	$GLOBALS["DELETED_FILES"]=0;
	
	$unix->events(basename(__FILE__).":: ".__FUNCTION__." initalize");
	init();
	$unix->events(basename(__FILE__).":: ".__FUNCTION__." cleanTmplogs()");
	cleanTmplogs();
	$unix->events(basename(__FILE__).":: ".__FUNCTION__." Cleaning /var/log");
	CleanDirLogs('/var/log');
	$unix->events(basename(__FILE__).":: ".__FUNCTION__." Cleaning /opt/artica/tmp");
	CleanDirLogs('/opt/artica/tmp');
	$unix->events(basename(__FILE__).":: ".__FUNCTION__." Cleaning /opt/artica/install");
	CleanDirLogs('/opt/artica/install');
	$unix->events(basename(__FILE__).":: ".__FUNCTION__." Cleaning phplogs");
	phplogs();

	$unix->events(basename(__FILE__).":: ".__FUNCTION__." Cleaning PHP Sessions");
	sessions_clean();
	$unix->events(basename(__FILE__).":: ".__FUNCTION__." Cleaning old install sources packages");

	
	$size=str_replace("&nbsp;"," ",FormatBytes($GLOBALS["DELETED_SIZE"]));
	echo "$size cleaned :  {$GLOBALS["DELETED_FILES"]} files\n";
	if($GLOBALS["DELETED_SIZE"]>500){
		send_email_events("$size logs files cleaned",
		"{$GLOBALS["DELETED_FILES"]} files cleaned for $size free disk space:\n
		".@implode("\n",$GLOBALS["UNLINKED"]),"logs_cleaning");
	}
	
	
}