Browse Source

More forking tweaks

rpm
J. King 3 years ago
parent
commit
e9394e8599
  1. 1
      lib/AbstractException.php
  2. 4
      lib/Service/Daemon.php
  3. 1
      locale/en.php

1
lib/AbstractException.php

@ -113,6 +113,7 @@ abstract class AbstractException extends \Exception {
"Service/Exception.pidDuplicate" => 10809,
"Service/Exception.pidLocked" => 10810,
"Service/Exception.pidInaccessible" => 10811,
"Service/Exception.forkFailed" => 10812,
];
protected $symbol;

4
lib/Service/Daemon.php

@ -30,7 +30,7 @@ class Daemon {
switch (@pcntl_fork()) {
case -1:
// Unable to fork
throw new \Exception("Unable to fork");
throw new Exception("forkFailed", ['instance' => 1]);
case 0:
fclose($pipe[0]);
# In the child, call setsid() to detach from any terminal and create an independent session.
@ -39,7 +39,7 @@ class Daemon {
switch (@pcntl_fork()) {
case -1:
// Unable to fork
throw new \Exception("Unable to fork");
throw new Exception("forkFailed", ['instance' => 2]);
case 0:
// We do some things out of order because as far as I know there's no way to reconnect stdin, stdout, and stderr without closing the channel to the parent first
# In the daemon process, write the daemon PID (as returned by getpid()) to a PID file, for example /run/foobar.pid (for a hypothetical daemon "foobar") to ensure that the daemon cannot be started more than once. This must be implemented in race-free fashion so that the PID file is only updated when it is verified at the same time that the PID previously stored in the PID file no longer exists or belongs to a foreign process.

1
locale/en.php

@ -219,4 +219,5 @@ return [
'Exception.JKingWeb/Arsse/Service/Exception.pidDuplicate' => 'Service is already running with process identifier {pid}',
'Exception.JKingWeb/Arsse/Service/Exception.pidLocked' => 'PID file "{pidfile}" is locked',
'Exception.JKingWeb/Arsse/Service/Exception.pidInaccessible' => 'Unable to open PID file "{pidfile}"',
'Exception.JKingWeb/Arsse/Service/Exception.forkFailed' => 'Failed to spawn child process ({instance, ordinal} instance)',
];

Loading…
Cancel
Save