Auto restart faxgetty when modem crash

Hi everybody in our world. I hope you have good health. Today I will paste my simple php code that I used in company server. My server got some problem that I don’t know what is source of this problem. I use Hylafax with Avantfax. Both of them update lasted version on Ubuntu 10.10. I know only it’s about segfault. I found some log at /var/log/messages and I don’t know anymore.

/…

I found php script in some website but I use 2 modem. (1 external 1 internal) That php script didn’t work so I modified script. It’s very simple version. I don’t put any license to it so you can modify it freely.

/ee

<?php
/**
* Check if faxgetty runs and if not restart the service
* It's about segfault. /var/log/messages
*
* For two modem by EThaiZone.com
*/

$process='faxgetty'; //process
$command="ps -Al -cmd| grep ".$process; //command !!!

ob_start();
passthru($command); //execute command
$result=ob_get_contents();
ob_end_clean();

if(preg_match('#'.$process.'\r?\n.+'.$process.'#', $result))
{
	echo "No problem. Faxgetty run fine.\n"; //OK
}
else
{
	echo "Restart hylafax\n";
	exec("service hylafax restart");
}

?>

Save it and run it via cronjob. I recommend to run every seconds because it don’t cause load on cpu that should worry. In my cron I put this.

* * * * *   php -q /checkfaxgetty.php

I hope this’s useful to you.  /bye

Leave a Reply