. * * 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 unixLucene extends Service { public $name; public $phpDir; private $shutdownScript; protected $indexerDir; protected $lucenePidFile; protected $luceneDir; protected $luceneSource; protected $luceneSourceLoc; protected $javaXms; protected $javaXmx; private $util = null; public function __construct() { } function load() { $this->name = "KTLuceneTest"; $this->util = new InstallUtil(); $this->setLuceneDir(SYSTEM_DIR."bin".DS."luceneserver".DS); $this->setIndexerDir(SYSTEM_DIR."search2".DS."indexing".DS."bin".DS); $this->setLucenePidFile("lucene_test.pid"); $this->setJavaXms(512); $this->setJavaXmx(512); $this->setLuceneSource("ktlucene.jar"); $this->setLuceneSourceLoc("ktlucene.jar"); $this->setPhpDir(); $this->setShutdownScript("shutdown.php"); } public function setIndexerDir($indexerDir) { $this->indexerDir = $indexerDir; } private function getIndexerDir() { return $this->indexerDir; } private function setShutdownScript($shutdownScript) { $this->shutdownScript = $shutdownScript; } public function getShutdownScript() { return $this->shutdownScript; } private function setPhpDir($phpdir = '') { if($phpdir == '') { $cmd = "whereis php"; $response = $this->util->pexec($cmd); if(is_array($response['out'])) { $broke = explode(' ', $response['out'][0]); foreach ($broke as $r) { $match = preg_match('/bin/', $r); if($match) { $this->phpDir = preg_replace('/php:/', '', $r); } } } return ; } else { $this->phpDir = $phpdir; } } public function getPhpDir() { return $this->phpDir; } private function setLucenePidFile($lucenePidFile) { $this->lucenePidFile = $lucenePidFile; } private function getLucenePidFile() { return $this->lucenePidFile; } private function setLuceneDir($luceneDir) { $this->luceneDir = $luceneDir; } public function getLuceneDir() { return $this->luceneDir; } private function setJavaXms($javaXms) { $this->javaXms = "-Xms$javaXms"; } public function getJavaXms() { return $this->javaXms; } private function setJavaXmx($javaXmx) { $this->javaXmx = "-Xmx$javaXmx"; } public function getJavaXmx() { return $this->javaXmx; } private function setLuceneSource($luceneSource) { $this->luceneSource = $luceneSource; } public function getLuceneSource() { return $this->luceneSource; } private function setLuceneSourceLoc($luceneSourceLoc) { $this->luceneSourceLoc = $this->getLuceneDir().$luceneSourceLoc; } public function getLuceneSourceLoc() { return $this->luceneSourceLoc; } public function getJavaOptions() { return " {$this->getJavaXmx()} {$this->getJavaXmx()} -jar "; } public function stop() { // TODO: Breaks things $state = $this->status(); if($state != 'STOPPED') { $cmd = "pkill -f ".$this->getLuceneSource(); $response = $this->util->pexec($cmd); return $response; } } public function install() { $state = $this->status(); if($state != 'STARTED') { $cmd = "cd ".$this->getLuceneDir()."; "; $cmd .= "nohup java -jar ".$this->getLuceneSource()." &> ".SYS_LOG_DIR."lucene.log &"; $response = $this->util->pexec($cmd); return $response; } elseif ($state == 'STOPPED') { // Start Service return true; } else { // Service Running Already return true; } return false; } public function status() { $cmd = "ps ax | grep ".$this->getLuceneSource(); $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'; } public function uninstall() { $this->stop(); } // Start lucene public function start() { } } ?>