public function run($args) { $logger = LoggerFactory::getFileLogger('check_processes'); $logger->log(__METHOD__ . ' Start checkprocesses command.'); $criteria = new CDbCriteria(); $criteria->compare('stopped', 0); $connections = Listener::model()->findAll($criteria); $logger->log(__METHOD__ . ' Found ' . count($connections) . ' connections.'); foreach ($connections as $connection) { $logger->log(__METHOD__ . ' Listener info:', array('process_pid' => $connection->process_pid, 'listener_id' => $connection->listener_id, 'source' => $connection->source)); if (ProcessPid::isActiveProcess($connection->process_pid) === false) { ListenerProcess::addComment($connection->listener_id, 'comment', 'System found out that process is not active any more. Process will be re-run right now.'); Listener::stopConnection($connection->listener_id, time()); Listener::runConnection($connection->source, $connection->additional_param, 'auto'); } } // ProcessPid::killProcess(12376); $synchronization = new Synchronization(); if ($synchronization->isProcessed() && ProcessPid::isActiveProcess($synchronization->getTcpServerPid()) === false) { $synchronization->startTcpServer(); } if ($synchronization->isProcessed() && ProcessPid::isActiveProcess($synchronization->getTcpClientPid()) === false) { $synchronization->startTcpClient(); } }
public function init() { parent::init(); ini_set('memory_limit', '-1'); set_time_limit(0); error_reporting(E_ALL & ~E_WARNING); date_default_timezone_set('UTC'); /** * For flexibility system */ $this->founded_in = date('YmdHis'); /** * Logger */ $this->logger = LoggerFactory::getFileLogger('SyncStatusCommand'); // $this->logger = LoggerFactory::getConsoleLogger(); /** * Settings */ $this->settings = new Synchronization(); /** * Check pid */ if ($this->settings->getSynsStatusCommandPid() && ProcessPid::isActiveProcess($this->settings->getSynsStatusCommandPid())) { exit; } else { $this->settings->setSynsStatusCommandPid(getmypid()); } /** * Connector */ $server = ['ip' => $this->settings->server_ip, 'port' => $this->settings->server_port]; $client = ['ip' => $this->settings->remote_server_ip, 'port' => $this->settings->remote_server_port]; $this->connector = new UDPConnector($this->logger, $server, $client); /** * Message */ $this->message_features = [SyncStatusHandler::MESSAGE_TYPE => 'S', SyncStatusHandler::MESSAGE_FROM => $this->settings->getIdentificator(), SyncStatusHandler::FOUNDED_IN => $this->founded_in]; }
public function test_IsActiveProcess() { $pid = getmypid(); $this->assertTrue(ProcessPid::isActiveProcess($pid)); }