public function init() { if (isset($GLOBALS['svc'])) { $this->service = $GLOBALS['svc']; $this->pid = $this->service['pid']; $this->id = $GLOBALS['svc_id']; $this->service['id'] = $this->id; unset($GLOBALS['svc']); unset($GLOBALS['svc_id']); ServiceManager::initLogAppend($this->id, "[OK]"); ServiceManager::markAsRunning($this->service['name'], $this->id, $this->service); if (isset($this->service['params'])) { $this->params = $this->service['params']; } ob_start(function ($data) { $this->logAppend("\n" . $data); return ""; }, 1); } else { echo <<<EOF ============================ WARNING ========================== You should start this service from Plansys Service Manager =============================================================== EOF; } }
public function actionExecute($id) { ServiceManager::initLogAppend($id, "[OK]"); $running = true; while ($running) { if (ServiceManager::hasMsg($id)) { $svc = ServiceManager::readMsg($id); if (is_array($svc)) { $running = false; $commandPath = Yii::getPathOfAlias($svc['commandPath']); $commandName = lcfirst(substr($svc['command'], 0, strlen($svc['command']) - 7)); $actionName = lcfirst(substr($svc['action'], 6)); $GLOBALS['svc'] = $svc; $GLOBALS['svc_id'] = $id; ServiceManager::initLog($id, str_pad("Starting {$svc['name']} [PID:{$svc['pid']}]", 45, ".")); $runner = new CConsoleCommandRunner(); $runner->addCommands($commandPath); $runner->run(['yiic', $commandName, $actionName]); } } } }