Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/daemon/control/PhabricatorDaemonReference.php
<?php | <?php | ||||
final class PhabricatorDaemonReference { | final class PhabricatorDaemonReference { | ||||
private $name; | private $name; | ||||
private $argv; | private $argv; | ||||
private $pid; | private $pid; | ||||
private $start; | private $start; | ||||
private $pidFile; | private $pidFile; | ||||
private $daemonLog; | private $daemonLog; | ||||
public static function newFromFile($path) { | |||||
$pid_data = Filesystem::readFile($path); | |||||
$dict = json_decode($pid_data, true); | |||||
if (!is_array($dict)) { | |||||
// Just return a hanging reference, since control code needs to be | |||||
// robust against unusual system states. | |||||
$dict = array(); | |||||
} | |||||
$ref = self::newFromDictionary($dict); | |||||
$ref->pidFile = $path; | |||||
return $ref; | |||||
} | |||||
public static function newFromDictionary(array $dict) { | public static function newFromDictionary(array $dict) { | ||||
$ref = new PhabricatorDaemonReference(); | $ref = new PhabricatorDaemonReference(); | ||||
$ref->name = idx($dict, 'name', 'Unknown'); | $ref->name = idx($dict, 'name', 'Unknown'); | ||||
$ref->argv = idx($dict, 'argv', array()); | $ref->argv = idx($dict, 'argv', array()); | ||||
$ref->pid = idx($dict, 'pid'); | $ref->pid = idx($dict, 'pid'); | ||||
$ref->start = idx($dict, 'start'); | $ref->start = idx($dict, 'start'); | ||||
$this->daemonLog = id(new PhabricatorDaemonLog())->loadOneWhere( | |||||
'daemon = %s AND pid = %d AND dateCreated = %d', | |||||
$this->name, | |||||
$this->pid, | |||||
$this->start); | |||||
epriestley: Static function, should be `$ref`. | |||||
return $ref; | return $ref; | ||||
} | } | ||||
public function updateStatus($new_status) { | public function updateStatus($new_status) { | ||||
try { | try { | ||||
if (!$this->daemonLog) { | if (!$this->daemonLog) { | ||||
$this->daemonLog = id(new PhabricatorDaemonLog())->loadOneWhere( | $this->daemonLog = id(new PhabricatorDaemonLog())->loadOneWhere( | ||||
'daemon = %s AND pid = %d AND dateCreated = %d', | 'daemon = %s AND pid = %d AND dateCreated = %d', | ||||
Show All 32 Lines | final class PhabricatorDaemonReference { | ||||
public function getArgv() { | public function getArgv() { | ||||
return $this->argv; | return $this->argv; | ||||
} | } | ||||
public function getEpochStarted() { | public function getEpochStarted() { | ||||
return $this->start; | return $this->start; | ||||
} | } | ||||
public function setPIDFile($pid_file) { | |||||
$this->pidFile = $pid_file; | |||||
return $this; | |||||
} | |||||
public function getPIDFile() { | public function getPIDFile() { | ||||
return $this->pidFile; | return $this->pidFile; | ||||
} | } | ||||
public function getDaemonLog() { | |||||
return $this->daemonLog; | |||||
} | |||||
public function isRunning() { | public function isRunning() { | ||||
return self::isProcessRunning($this->getPID()); | return self::isProcessRunning($this->getPID()); | ||||
} | } | ||||
public static function isProcessRunning($pid) { | public static function isProcessRunning($pid) { | ||||
if (!$pid) { | if (!$pid) { | ||||
return false; | return false; | ||||
} | } | ||||
Show All 33 Lines |
Static function, should be $ref.