public function __invoke() { try { $this->acquireLock(); $this->execCommand(); } catch (RuntimeException $e) { $this->releaseLock(); echo $e->getMessage(), PHP_EOL; return false; } catch (LockException $e) { $locker = $this->pidFile->getPid(); if ($this->processManager->isProcessRunning($locker)) { $this->debug('Command was already executed with PID ', $locker); return false; } $this->debug($locker . ' lock released'); $this->releaseLock(); $this->acquireLock(); $this->execCommand(); } return true; }
function restartLsyncd($APP_CONF) { $processManager = new ProcessManager(); $pidFile = $APP_CONF['data_dir'] . 'lsyncd.pid'; if (file_exists($pidFile)) { $pid = file_get_contents($pidFile); if ($processManager->isProcessRunning($pid)) { echo "Stopping existing Lsyncd.\n"; $processManager->killProcess($pid); } } echo "Starting Lsyncd.\n"; startLsyncd($APP_CONF); }