. * * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * * @copyright 2008-2009, KnowledgeTree Inc. * @license GNU General Public License version 3 * @author KnowledgeTree Team * @package Installer * @version Version 0.1 */ class unixScheduler extends Service { public $name; public $phpDir; protected $schedulerPidFile; protected $schedulerDir; protected $schedulerSource; protected $schedulerSourceLoc; protected $systemDir; private $util = null; public function __construct() { } function load() { $this->name = "KTSchedulerTest"; $this->util = new InstallUtil(); $this->setSystemDir(SYSTEM_ROOT."bin".DS); $this->setSchedulerDir(SYSTEM_DIR."bin".DS); $this->setSchedulerSource('schedulerTask.sh'); $this->setSchedulerSourceLoc('schedulerTask.sh'); $this->setSchedulerPidFile("scheduler_test.pid"); } private function setSchedulerPidFile($schedulerPidFile) { $this->schedulerPidFile = $schedulerPidFile; } private function getSchedulerPidFile() { return $this->schedulerPidFile; } function setSystemDir($systemDir) { $this->systemDir = $systemDir; } function getSystemDir() { if(file_exists($this->systemDir)) return $this->systemDir; return false; } function setSchedulerDir($schedulerDir) { $this->schedulerDir = $schedulerDir; } function getSchedulerDir() { return $this->schedulerDir; } function setSchedulerSource($schedulerSource) { $this->schedulerSource = $schedulerSource; } function getSchedulerSource() { return $this->schedulerSource; } function setSchedulerSourceLoc($schedulerSourceLoc) { $this->schedulerSourceLoc = $this->getSchedulerDir().$schedulerSourceLoc; } function getSchedulerSourceLoc() { if(file_exists($this->schedulerSourceLoc)) return $this->schedulerSourceLoc; return false; } function install() { // $source = $this->getSchedulerSourceLoc(); // if($source) { // $cmd = "nohup ".$source." &> ".SYS_LOG_DIR."dmsctl.log"; // $response = $this->util->pexec($cmd); // return $response; // } else { // $source = $this->getSystemDir().$this->schedulerSource; // if(file_exists($source)) { // $cmd = "nohup ".$source." &> ".SYS_LOG_DIR."dmsctl.log"; // $response = $this->util->pexec($cmd); // return $response; // } // } return false; } function uninstall() { $this->stop(); } function stop() { $cmd = "pkill -f ".$this->schedulerSource; $response = $this->util->pexec($cmd); return $response; } function status() { $cmd = "ps ax | grep ".$this->getSchedulerSource(); $response = $this->util->pexec($cmd); if(is_array($response['out'])) { if(count($response['out']) > 1) { foreach ($response['out'] as $r) { preg_match('/grep/', $r, $matches); // Ignore grep if(!$matches) { return 'STARTED'; } } } else { return 'STOPPED'; } } return 'STOPPED'; } function writeSchedulerTask() { $fp = fopen($this->getSchedulerDir().$this->getSchedulerSource(), "w+"); $content = "#!/bin/sh\n"; $content .= "cd ".$this->getSchedulerDir()."\n"; $content .= "while true; do\n"; $content .= "php "."\"{$this->getSchedulerDir()}{$this->getSchedulerSource()}\""; $content .= "sleep 30\n"; $content .= "done"; fwrite($fp, $content); fclose($fp); } } ?>