Handles UNIX signals

SIGTERM and SIGINT can be used to trigger a clean shutdown of
this server.

@param integer $signal the signal received.

@return void
760872
public function handleSignal($signal)
    {
        switch ($signal) {
        case SIGINT:
            $this->log(
                'Received SIGINT, shutting down.' . PHP_EOL,
                Net_Notifier_Logger::VERBOSITY_ALL
            );
            $this->moribund = true;
            break;

        case SIGTERM:
            $this->log(
                'Received SIGTERM, shutting down.' . PHP_EOL,
                Net_Notifier_Logger::VERBOSITY_ALL
            );
            $this->moribund = true;
            break;
        }
    }
376101
public function flagShutdown(string $message = null): void
    {
        $this->isShutdown = true;
        $this->shutdownMessage = (null === $message ? 'Daemon flagged for shutdown' : $message);
    }
886834
public function kill($signal = SIGKILL)
    {
        if (!$this->getPid()) {
            throw new ResqueRuntimeException(
                'Cannot kill a process with out a pid set'
            );
        }

        //TODO: needs logger
        //$this->getLogger()->notice('Sending {signal} to process {pid}', array('signal'=>$signal, 'pid'=>$this->getPid()));

        // @todo Work out if I care to check the result, and if I did what to do about it... Exception?
        posix_kill($this->getPid(), $signal);

        $this->pid = null;

        return $this;
    }
335493
public function receive(Signal $signal)
    {
        if (!$signal instanceof Signal\LocationService\HideLocationSignal) {
            return;
        }

        $this->indexSubtree($signal->locationId);
    }
249387
public function receive(Signal $signal)
    {
        if (!$signal instanceof Signal\LocationService\SwapLocationSignal) {
            return;
        }

        $this->runLegacyKernelCallback(
            static function () use ($signal) {
                eZContentCacheManager::clearContentCacheIfNeeded($signal->content1Id);
                eZContentCacheManager::clearContentCacheIfNeeded($signal->content2Id);
                eZSearch::swapNode($signal->location1Id, $signal->location2Id);
                eZContentObject::clearCache(); // Clear all object memory cache to free memory
            }
        );
    }
772204
public function receive(Signal $signal)
    {
        if (!$signal instanceof Signal\LocationService\UnhideLocationSignal) {
            return;
        }

        $this->indexSubtree($signal->locationId);
    }
1335398
public static function signal_handler($signo) {
        // Note: There is no need to manually call the shutdown handler.
        // The fact that we are calling exit() in this script means that the standard shutdown handling is performed
        // anyway.
        switch ($signo) {
            case SIGTERM:
                // Replicate native behaviour.
                echo "Terminated: {$signo}\n";

                // The standard exit code for SIGTERM is 143.
                $exitcode = 143;
                break;
            case SIGINT:
                // Replicate native behaviour.
                echo "\n";

                // The standard exit code for SIGINT (Ctrl+C) is 130.
                $exitcode = 130;
                break;
            default:
                // The signal handler was called with a signal it was not expecting.
                // We should exit and complain.
                echo "Warning: \core_shutdown_manager::signal_handler() was called with an unexpected signal ({$signo}).\n";
                $exitcode = 1;
        }

        exit ($exitcode);
    }
141800
public function receive(Signal $signal)
    {
        if (!$signal instanceof Signal\TrashService\TrashSignal) {
            return;
        }

        if ($signal->contentTrashed) {
            $this->searchHandler->deleteContent(
                $signal->contentId
            );
        }

        $this->searchHandler->deleteLocation(
            $signal->locationId,
            $signal->contentId
        );
    }
232673
public function receive(Signal $signal)
    {
        if (!$signal instanceof Signal\LocationService\CreateLocationSignal) {
            return;
        }

        $this->runLegacyKernelCallback(
            static function () use ($signal) {
                eZContentCacheManager::clearContentCacheIfNeeded($signal->contentId, true, [$signal->locationId]);
                $object = eZContentObject::fetch($signal->contentId);
                eZSearch::addNodeAssignment($object->mainNodeID(), $signal->contentId, $signal->locationId);
                eZContentObject::clearCache(); // Clear all object memory cache to free memory
            }
        );
    }
774425
public function receive(Signal $signal)
    {
        if (!$signal instanceof Signal\ObjectStateService\SetPriorityOfObjectStateSignal) {
            return;
        }

        parent::receive($signal);
    }
421489
public function receive(Signal $signal)
    {
        if (!$signal instanceof Signal\ContentService\CopyContentSignal) {
            return;
        }

        $this->searchHandler->indexContent(
            $this->persistenceHandler->contentHandler()->load(
                $signal->dstContentId,
                $signal->dstVersionNo
            )
        );

        $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent(
            $signal->dstContentId
        );
        foreach ($locations as $location) {
            $this->searchHandler->indexLocation($location);
        }
    }
78027
def _handle_terminate(self, signal_number, _):
        """"""
        signal_names = {
            signal.SIGINT: 'SIGINT',
            signal.SIGQUIT: 'SIGQUIT',
            signal.SIGTERM: 'SIGTERM',
        }
        message = 'Terminated by {name} ({number})'.format(
            name=signal_names[signal_number], number=signal_number)
        self._shutdown(message, code=128+signal_number)
349135
public function handleSignal(int $signal) {
        $this->log(LogLevel::DEBUG, "[{pid}] Caught signal '{$signal}'");

        switch ($signal) {

            // Daemon was asked to hang up
            case SIGHUP:
                if ($this->realm == 'daemon') {
                    $handled = $this->payloadExec('signal', [$signal]);
                    if (!$handled) {
                        throw new Exception("Restart", 100);
                    }
                }
                break;

            // Daemon is exiting, kill children
            case SIGINT:
            case SIGTERM:
                if ($this->realm == 'daemon') {
                    if ($this->instance) {
                        if (is_callable([$this->instance, 'shutdown'])) {
                            $this->instance->shutdown();
                        }
                    }
                    $this->reapAllChildren();
                    $this->payloadExec('signal', [$signal]);
                    throw new Exception("Shutdown", 200);
                }
                break;

            // Child process exited
            case SIGCHLD:
                if ($this->realm == 'daemon') {
                    do {
                        $status = null;
                        $pid = pcntl_wait($status, WNOHANG);
                        if ($pid > 0) {
                            $this->reapChild($pid, $status);
                        }
                    } while ($pid > 0);

                    //$pid = pcntl_waitpid(-1, $status, WNOHANG);
                    //if ($pid > 0)
                    //   $this->land($pid, $status);
                }
                break;

            // Custom signal - Nothing
            case SIGUSR1:
                $this->payloadExec('signal', [$signal]);
                break;

            // Custom signal - Nothing
            case SIGUSR2:
                $this->payloadExec('signal', [$signal]);
                break;
        }
    }
281360
public function receive(Signal $signal)
    {
        if (!$signal instanceof Signal\LocationService\DeleteLocationSignal) {
            return;
        }

        $this->searchHandler->deleteLocation(
            $signal->locationId,
            $signal->contentId
        );
    }
584648
final public function shutdown(int $sig = 0) : void
    {
        // check exiting state
        if ($this->exiting) {
            return;
        }

        $this->exiting = true;

        // be wait
        $wait = Promise::deferred();

        // user-land stopping
        $this->stopping($wait);

        // trigger event::program::stopped
        $this->action(Program::STOPPED);

        // waiting
        $wait->then(function () use ($sig) {
            $this->exited($sig);
        }, function (Throwable $e) use ($sig) {
            $this->exited($sig, $e);
        });
    }
849077
public function signalToEvent($signal) {

        if ( $this->pid == ProcessTools::getPid() ) {

            $signame = $this->signals->signame($signal);

            $this->logger->debug("Received $signame ($signal) signal, firing associated event(s)");

            $this->events->emit(new PosixEvent($signal, $this));
            $this->events->emit(new PosixEvent($signame, $this));

        }

        return $this;

    }
403013
public function receive(Signal $signal)
    {
        if (!$signal instanceof Signal\LocationService\UpdateLocationSignal) {
            return;
        }

        $this->runLegacyKernelCallback(
            static function () use ($signal) {
                eZContentCacheManager::clearContentCacheIfNeeded($signal->contentId);
                eZContentObject::clearCache(); // Clear all object memory cache to free memory
            }
        );
    }