Example #1
0
 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 startLsyncd($APP_CONF)
{
    $processManager = new ProcessManager();
    $pidFile = $APP_CONF['data_dir'] . 'lsyncd.pid';
    $command = $APP_CONF['path_to_lsyncd'] . ' ' . $APP_CONF['data_dir'] . 'lsyncd.conf.lua';
    if (isset($APP_CONF['dry_run']) && $APP_CONF['dry_run']) {
        $command = 'sleep 60';
    }
    $pid = $processManager->execProcess($command);
    file_put_contents($pidFile, $pid);
    echo "Lsyncd started. Pid: {$pid}.\n";
    return;
}