Location: PHPKode > projects > Slashster > slashster/cron/isscheduler.php
#!/usr/local/bin/php
<?

# Slashster: Open Source Friend of a Friend Software
# Copyright 2004 Mark El-Wakil
# Contact: hide@address.com
# http://seventhcycle.net
#
# This file is part of Slashster.
#
# Slashster is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Slashster is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Slashster; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

   require("cronpth.php");       
   $mpage = new PageClass("sqlonly");

   $dire = $mpage->sys[siteroot] .  "cron";

   if ($argv[1] == "stop")
   {
       foreach ($flelst as $k => $v)
       {
          KillProc($k, $v);
       }

       echo "Killing Processes\n\n";
       exit;
   }


   foreach ($flelst as $k => $v)
   {
       FuncTest($k, $v);
   }

function KillProc($v, $fl)
{
   global $dire;
 
   ob_start();
   readfile("$dire/schedule$v.pid");
   $pid = ob_get_contents();
   ob_end_clean();

   if (!is_numeric($pid)) return;

   echo "Killing pid: $pid, $fl\n";

   posix_kill($pid,15);
   unlink("$dire/schedule$v.pid");
}

function FuncTest($v, $fl)
{
   global $dire, $mpage;

   ob_start();
   @readfile("$dire/schedule$v.pid");
   $pid = ob_get_contents();
   ob_end_clean();   

   if ($pid)
   {
       $sys = "ps $pid";
       ob_start();
       system($sys, $ret);
       $g = ob_get_contents();
       ob_end_clean();
  
       $str = "$pid";
   }

   $cmd = "$dire/$fl > /dev/null &";

   if (!stristr($g, $str))
   {
       system($cmd);
       $st = "started up";
       mail($mpage->adm[email], $mpage->sys[sitename].": status $fl", "");
   }
   else
   {
       $st = "present";
   }

   echo "$st\n$cmd\n";
}

?>
Return current item: Slashster