Results 1 to 3 of 3
-
1st Dec 2010, 06:27 AM #1OPRespected DeveloperWebsite's:
X4B.orgSplitIce Sever Process Checker
This script restarts processes that have died/segfaulted. Wont protect against defuncts or anything like that but its a basic start. Also checks that certain processes dont exceed a set memory usage and if they do can execute a php function or shell command.
Run via CLI, as root.
PHP Code:<?php
/* SplitIce Sever Process Checker */
/* Version: 1.2 */
/* All distributed versions must keep this header intact */
/* Need software development work? Contact me: fast, reasonable rates */
$_CONFIG = array();
/* Process is running checks */
$_CONFIG['CHECKS'] = array(
/* Substring to check for => Command to run if not found */
'nginx: worker process'=>'/etc/init.d/nginx restart',
'nginx: master process /usr/sbin/nginx'=>'/etc/init.d/nginx restart',
'/usr/bin/php5-fpm'=>'/etc/init.d/php5-fpm restart',
'searchd' => '/usr/local/bin/searchd'
);
/* Process memory limits */
$_CONFIG['MEM'] = array(
/* Substring to check for => array(max memory,command to run if exceeds) */
/* Size in KB */
/* if command is an array then it is treated as a callback (php function) */
'searchd'=>array(1024*1024,array('searchd_restart'))
);
/* Example Callback for Memory checks */
function searchd_restart($PID){
/* This example deals with the memory leaks in the sphinx daemon */
exec('killall searchd');//Nice kill
exec('killall -2 searchd');//agrivated kill
Sleep(1);
exec('killall -3 searchd');//angy kill
exec('killall -4 searchd');//skitzo kill
passthru('/usr/local/bin/searchd');//reborn :D
}
/* Program Starts */
function processes(){
$processes = array();
foreach(glob('/proc/*/cmdline') as $p){
$pt = explode('/',$p);
if(is_numeric($pt[2])) {
if($CMD = file_get_contents($p)) {
$processes[$pt[2]] = trim($CMD);
}
}
}
return $processes;
}
function process_mem($PID){
$data = file('/proc/'.$PID.'/status');
foreach($data as $v){
if(!substr_compare($v,'VmRSS:',0,6)){
$t = trim(substr($v,7));
$t = trim(substr($t,0,strpos($t,' ')));
return (int)$t;
}
}
return false;
}
$CHECKS = array();
while(true){
$processes = processes();
foreach($_CONFIG['CHECKS'] as $m=>$cmd){
$check = false;
foreach($processes as $PID=>$p){
if(stripos($p,$m)!==false){
$check = true;
break;
}
}
if(!$check){
passthru($cmd);
Sleep(5);//Multi-Teired Check delay
}
}
foreach ($_CONFIG['MEM'] as $process=>$data){
$check = false;
foreach($processes as $PID=>$p){
if(stripos($p,$process)!==false){
$check = $PID;
break;
}
}
if($check){
if(process_mem($check)>$data[0]){
if(is_array($data[1])){
call_user_func($data[1][0],$check);
}else{
passthru($data[1]);
}
Sleep(5);//Multi-Teired Check delay
}
}
}
Sleep(30);
}
?>SplitIce Reviewed by SplitIce on . SplitIce Sever Process Checker This script restarts processes that have died/segfaulted. Wont protect against defuncts or anything like that but its a basic start. Also checks that certain processes dont exceed a set memory usage and if they do can execute a php function or shell command. Run via CLI, as root. <?php /* SplitIce Sever Process Checker */ /* Version: 1.2 */ /* All distributed versions must keep this header intact */ /* Need software development work? Contact me: fast, reasonable rates Rating: 5
-
30th Jan 2011, 11:55 AM #2Respected MemberWebsite's:
DL4Everything.com Soft2050.inhow to run it but?
a little more explanation plz..
-
30th Jan 2011, 11:59 AM #3OPRespected DeveloperWebsite's:
X4B.org
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Does anyone have SplitIce ioncube decoder?
By soogoomoo in forum Web Development AreaReplies: 10Last Post: 23rd Feb 2011, 11:14 AM -
[FREE] SplitIce's Crazy Giveaway [$5].
By SplitIce in forum Completed TransactionsReplies: 15Last Post: 5th Feb 2011, 12:55 PM
themaPoster - post to forums and...
Version 5.22 released. Open older version (or...