Changeset View
Standalone View
src/daemon/overseer/PhutilDaemonOverseer.php
| Show All 11 Lines | |||||
| * Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
| * distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| /** | /** | ||||
| * Oversees a daemon and restarts it if it fails. | * Oversees a daemon and restarts it if it fails. | ||||
akopanev: Yes, comments are good!
Testing phabricator.... | |||||
| * | * | ||||
| * @group daemon | * @group daemon | ||||
| */ | */ | ||||
| class PhutilDaemonOverseer { | class PhutilDaemonOverseer { | ||||
Not Done Inline ActionsGood use of 'class' keyword eep: Good use of 'class' keyword | |||||
Not Done Inline Actionsinline comment. briany12: inline comment. | |||||
Not Done Inline ActionsYep. Big fan. eep: Yep. Big fan. | |||||
Not Done Inline ActionsDown with the Bourgeoisie class system! test13254: Down with the Bourgeoisie class system! | |||||
| private $captureBufferSize = 65536; | private $captureBufferSize = 65536; | ||||
| private $deadline; | private $deadline; | ||||
| private $deadlineTimeout = 86400; | private $deadlineTimeout = 86400; | ||||
Not Done Inline ActionsI added this comment dheerendra: I added this comment | |||||
| private $restartDelay = 60; | private $restartDelay = 60; | ||||
| private $killDelay = 3; | private $killDelay = 3; | ||||
Not Done Inline ActionsMy comment dheerendra: My comment | |||||
| private $daemon; | private $daemon; | ||||
| private $argv; | private $argv; | ||||
Not Done Inline Actionsthis works, why private, mutable states oh! _bhaisaab: this works, why private, mutable states oh! | |||||
Not Done Inline ActionsRe comment dheerendra: Re comment | |||||
| private $childPID; | private $childPID; | ||||
Not Done Inline Actions? WouterSioen: ? | |||||
| private $signaled; | private $signaled; | ||||
Not Done Inline ActionsHello world! :) a.veretennikov: Hello world! :) | |||||
| private static $instance; | private static $instance; | ||||
| private $traceMode; | private $traceMode; | ||||
| private $traceMemory; | private $traceMemory; | ||||
| private $daemonize; | private $daemonize; | ||||
Not Done Inline ActionsFoobar lasseespeholt: Foobar | |||||
| private $phddir; | private $phddir; | ||||
| private $conduit; | |||||
Not Done Inline Actionstest ganesanramkumar: test | |||||
Not Done Inline Actionstest1 ganesanramkumar: test1 | |||||
Not Done Inline Actionstest11 sunzhen1991: test11 | |||||
Not Done Inline ActionsI can reply too!!!!!! dheerendra: I can reply too!!!!!! | |||||
| private $conduitURI; | private $conduitURI; | ||||
Not Done Inline Actions@sunzhen How can I repy you dheerendra: @sunzhen How can I repy you | |||||
| public function __construct($daemon, array $argv) { | public function __construct($daemon, array $argv) { | ||||
| $this->daemon = $daemon; | $this->daemon = $daemon; | ||||
| $original_argv = $argv; | $original_argv = $argv; | ||||
| $len = count($argv); | $len = count($argv); | ||||
| for ($ii = 1; $ii < $len; $ii++) { | for ($ii = 1; $ii < $len; $ii++) { | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | public function __construct($daemon, array $argv) { | ||||
| declare(ticks = 1); | declare(ticks = 1); | ||||
| pcntl_signal(SIGUSR1, array($this, 'didReceiveKeepaliveSignal')); | pcntl_signal(SIGUSR1, array($this, 'didReceiveKeepaliveSignal')); | ||||
| pcntl_signal(SIGINT, array($this, 'didReceiveTerminalSignal')); | pcntl_signal(SIGINT, array($this, 'didReceiveTerminalSignal')); | ||||
| pcntl_signal(SIGTERM, array($this, 'didReceiveTerminalSignal')); | pcntl_signal(SIGTERM, array($this, 'didReceiveTerminalSignal')); | ||||
| } | } | ||||
| public function run() { | public function run() { | ||||
Not Done Inline ActionsИ придраться-то не к чему :) lukianovva: И придраться-то не к чему :) | |||||
| if (!$this->traceMode) { | if (!$this->traceMode) { | ||||
| echo "Running daemon '{$this->daemon}' silently. Use '--trace' to ". | echo "Running daemon '{$this->daemon}' silently. Use '--trace' to ". | ||||
| "produce debugging output.\n"; | "produce debugging output.\n"; | ||||
| } | } | ||||
| $root = phutil_get_library_root('phutil'); | $root = phutil_get_library_root('phutil'); | ||||
Not Done Inline ActionsTihsihsidhs shaneduffy: Tihsihsidhs
| |||||
Not Done Inline Actionstesting shaneduffy: testing | |||||
| $root = dirname($root); | $root = dirname($root); | ||||
Not Done Inline Actionsfswfksjflksdjf sharatjy: fswfksjflksdjf | |||||
Not Done Inline ActionsSeems like OK adil.atilgan: Seems like OK | |||||
| $exec_dir = $root.'/scripts/daemon/exec/'; | $exec_dir = $root.'/scripts/daemon/exec/'; | ||||
Not Done Inline ActionsMUCH ROOT! SUCH COMMENT! satbirjhuti: MUCH ROOT! SUCH COMMENT! | |||||
| // NOTE: In Ubuntu, this command is executed via an intermediary shell | |||||
| // due to some awkward implemenation artifact beyond our control. | |||||
| // We use 'exec' to replace it with the real process; without this, | |||||
| // the child will call posix_getppid(), be given the pid of the 'sh -c' | |||||
| // process, and send it SIGUSR1 to keepalive which will terminate it | |||||
| // immediately. We also won't be able to do process group management | |||||
| // because the shell process won't properly posix_setsid() so the pgid | |||||
Not Done Inline Actionscomment for a comment? taligahack: **//comment for a comment?//** | |||||
Not Done Inline Actionstest tomlinsonryan: test | |||||
Not Done Inline Actionscomment puneet: comment
| |||||
Not Done Inline Actionstest dsflksadjflkdsajflkdsajfldsajfldsafds puneet: test dsflksadjflkdsajflkdsajfldsajfldsafds | |||||
Not Done Inline Actionsyour comment is extremely helpful manako: your comment is extremely helpful | |||||
| // of the child won't be meaningful. | |||||
| $exec_daemon = './exec_daemon.php'; | $exec_daemon = './exec_daemon.php'; | ||||
Not Done Inline Actionsggg 113madixing2: ggg | |||||
| $argv = $this->argv; | $argv = $this->argv; | ||||
| array_unshift($argv, $exec_daemon, $this->daemon); | array_unshift($argv, 'exec', $exec_daemon, $this->daemon); | ||||
Not Done Inline ActionsClosing parenthesis of a multi-line function call must be on a line by itself (at line 89) spanitz: Closing parenthesis of a multi-line function call must be on a line by itself (at line 89) | |||||
| foreach ($argv as $k => $arg) { | foreach ($argv as $k => $arg) { | ||||
| $argv[$k] = escapeshellarg($arg); | $argv[$k] = escapeshellarg($arg); | ||||
Not Done Inline Actionstesting suwandi.cahyadi: testing | |||||
Not Done Inline Actionstesting... akopanev: testing... | |||||
Not Done Inline ActionsThis is a testing annotation feynman: This is a testing annotation | |||||
Not Done Inline Actionstest reply w31rd0: test reply | |||||
Not Done Inline Actionsreply to test reply w31rd0: reply to test reply | |||||
| } | } | ||||
| $command = implode(' ', $argv); | $command = implode(' ', $argv); | ||||
| while (true) { | while (true) { | ||||
| $this->logMessage('INIT', 'Starting process.'); | $this->logMessage('INIT', 'Starting process.'); | ||||
Not Done Inline ActionsAnother test BYK: Another test | |||||
Not Done Inline Actionstest ramk: test | |||||
Not Done Inline Actionsreplying suwandi.cahyadi: replying
| |||||
Not Done Inline Actionstest reply galetzka.michael: test reply | |||||
| $future = new ExecFuture($command); | $future = new ExecFuture($command); | ||||
| $future->setCWD($exec_dir); | $future->setCWD($exec_dir); | ||||
Not Done Inline Actionskkk sharatjy: kkk | |||||
| $future->setStdoutSizeLimit($this->captureBufferSize); | $future->setStdoutSizeLimit($this->captureBufferSize); | ||||
| $future->setStderrSizeLimit($this->captureBufferSize); | $future->setStderrSizeLimit($this->captureBufferSize); | ||||
| $this->deadline = time() + $this->deadlineTimeout; | $this->deadline = time() + $this->deadlineTimeout; | ||||
Not Done Inline ActionsI like the idea of having the future executed... jackdmf: I like the idea of having the future executed... | |||||
| $future->isReady(); | $future->isReady(); | ||||
| $this->childPID = $future->getPID(); | $this->childPID = $future->getPID(); | ||||
| do { | do { | ||||
| do { | do { | ||||
| if ($this->traceMemory) { | if ($this->traceMemory) { | ||||
Not Done Inline Actionstoo deep cmodien: too deep | |||||
| $memuse = number_format(memory_get_usage() / 1024, 1); | $memuse = number_format(memory_get_usage() / 1024, 1); | ||||
| $this->logMessage('RAMS', 'Overseer Memory Usage: '.$memuse.' KB'); | $this->logMessage('RAMS', 'Overseer Memory Usage: '.$memuse.' KB'); | ||||
| } | } | ||||
Not Done Inline Actions
fabianbuch: * foo
* bar | |||||
| // We need a shortish timeout here so we can run the tick handler | // We need a shortish timeout here so we can run the tick handler | ||||
| // frequently in order to process signals. | // frequently in order to process signals. | ||||
| $result = $future->resolve(1); | $result = $future->resolve(1); | ||||
Not Done Inline ActionsLast line test RadeoslawPL: Last line test | |||||
Not Done Inline ActionsI expect you also mean foo and bar as fabian suggested above... It's definitely safer to use foo but if you want it to run fast and you're not worried by the occasional fooble meltdown then you can use bar here too. testleg: I expect you also mean foo and bar as fabian suggested above... It's definitely safer to use… | |||||
| if ($this->traceMode || $this->conduit) { | if ($this->traceMode || $this->conduit) { | ||||
| list($stdout, $stderr) = $future->read(); | list($stdout, $stderr) = $future->read(); | ||||
| $stdout = trim($stdout); | $stdout = trim($stdout); | ||||
Not Done Inline ActionsMultiline comment shoo ulziibay: Multiline comment shoo | |||||
| $stderr = trim($stderr); | $stderr = trim($stderr); | ||||
| if (strlen($stdout)) { | if (strlen($stdout)) { | ||||
| $this->logMessage('STDO', $stdout, $stdout); | $this->logMessage('STDO', $stdout, $stdout); | ||||
| } | } | ||||
| if (strlen($stderr)) { | if (strlen($stderr)) { | ||||
Not Done Inline Actionsyay tommycrush: yay | |||||
| $this->logMessage('STDE', $stderr, $stderr); | $this->logMessage('STDE', $stderr, $stderr); | ||||
| } | } | ||||
| $future->discardBuffers(); | $future->discardBuffers(); | ||||
Not Done Inline ActionsHit the road, buffers, and doncha come back no more, no more, no more, no more. JimJam: Hit the road, buffers, and doncha come back no more, no more, no more, no more. | |||||
| } | } | ||||
| if ($result !== null) { | if ($result !== null) { | ||||
| list($err) = $result; | list($err) = $result; | ||||
| if ($err) { | if ($err) { | ||||
| $this->logMessage( | $this->logMessage( | ||||
| 'FAIL', | 'FAIL', | ||||
| 'Process exited with error '.$err.'.', | 'Process exited with error '.$err.'.', | ||||
Not Done Inline Actionsgah tommycrush: gah | |||||
| $err); | $err); | ||||
| } else { | } else { | ||||
| $this->logMessage('DONE', 'Process exited successfully.'); | $this->logMessage('DONE', 'Process exited successfully.'); | ||||
| } | } | ||||
| break 2; | break 2; | ||||
| } | } | ||||
| } while (time() < $this->deadline); | } while (time() < $this->deadline); | ||||
| ▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines | |||||
Yes, comments are good!
Testing phabricator....