Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
function count_process($process_name)
{
	// check process in the process list
	$bot_count_cmd = "ps aux | grep \"{$process_name}\" | wc -l";
	$bot_count=shell_exec($bot_count_cmd);
	$bot_count=intval( trim($bot_count) )/-2; // you may need to tune the number based on your running environment

	return $bot_count;
}

...

Code Block
// check encoding.php in the process list
$bot_count=process_count("php encoding.php");

// we will just keep max 2 encoding bots
if (($bot_count)>2) exit;


Below is another example to check redis and restart its demon

Code Block
titlecheck_redis.sh
#!/bin/php
<?
function count_process($process_name)
{
        $cmd = "ps aux | grep \"{$process_name}\"";
        $res=shell_exec($cmd);
        echo $res . "\n";

        // check process in the process list
        $bot_count_cmd = "ps aux | grep \"{$process_name}\" | wc -l";
        $bot_count=shell_exec($bot_count_cmd);
        $bot_count=intval( trim($bot_count)-2 ); // you may need to tune the number based on your running environment

        return $bot_count;
}

if (count_process("redis-server")<1)
{
        shell_exec("sudo service redis restart");
}

?>