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 checkPreparingProcess() { if (ProcessPid::isActive('process_message') === false) { $command = Yii::app()->params['applications']['php_exe_path'] . " -f " . Yii::app()->params['applications']['console_app_path'] . " prepare"; It::runAsynchCommand($command); } }
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]; }
protected function stopTcpServer() { ProcessPid::killProcess($this->tcp_server_command_pid); $this->_configForm->updateParam('TCP_SERVER_COMMAND_PID', false); $this->_configForm->saveToFile(); }
public function actionStopListening() { if (!$_REQUEST['source']) { echo json_encode(array('errors' => array('Unknown connection type'))); Yii::app()->end(); } $source = strtoupper($_REQUEST['source']); $last_connection = Listener::getLastConnectionInfo($source); if ($last_connection && !$last_connection['stopped']) { ProcessPid::killProcess($last_connection['process_pid']); ListenerProcess::addComment($last_connection['listener_id'], 'comment', 'Stop by user'); Listener::stopConnection($last_connection['listener_id']); } echo json_encode(array('ok' => 1)); Yii::app()->end(); }
/** * Checks if file locked * * @param string $process_name file name * @return boolean */ public static function isLocked($process_name = 'process_message') { $pidfile = ProcessPid::getDir() . DIRECTORY_SEPARATOR . $process_name . '.lock'; $running_pid = 0; if (file_exists($pidfile)) { $size = @filesize($pidfile); $running_pid = @file_get_contents($pidfile); if ($size > 0 && $running_pid == false) { return true; } } return false; }
public function test_IsActiveProcess() { $pid = getmypid(); $this->assertTrue(ProcessPid::isActiveProcess($pid)); }