Restart the http server

@Usage {fullCommand} [-d|--daemon]
@Options
-d, --daemon    Run server on the background
@Example
{fullCommand}
{fullCommand} -d
@throws \Swoft\Exception\RuntimeException
@throws \InvalidArgumentException
@throws \RuntimeException
19453
public function restart()
    {
        $httpServer = $this->getHttpServer();

        // 是否已启动
        if ($httpServer->isRunning()) {
            $this->stop();
        }

        // 重启默认是守护进程
        $httpServer->setDaemonize();
        $this->start();
    }
806959
def run(options, http_req_handler = HttpReqHandler):
    
    # pylint: disable-msg=W0613
    global _HTTP_SERVER

    for x in ('server_version', 'sys_version'):
        if _OPTIONS.get(x) is not None:
            setattr(http_req_handler, x, _OPTIONS[x])

    _HTTP_SERVER = threading_tcp_server.KillableThreadingHTTPServer(
                       _OPTIONS,
                       (_OPTIONS['listen_addr'], _OPTIONS['listen_port']),
                       http_req_handler,
                       name = "httpdis")

    for name, cmd in _COMMANDS.iteritems():
        if cmd.at_start:
            LOG.info("at_start: %r", name)
            cmd.at_start(options)

    LOG.info("will now serve")
    while not _KILLED:
        try:
            _HTTP_SERVER.serve_until_killed()
        except (socket.error, select.error), why:
            if errno.EINTR == why[0]:
                LOG.debug("interrupted system call")
            elif errno.EBADF == why[0] and _KILLED:
                LOG.debug("server close")
            else:
                raise

    LOG.info("exiting")
924691
public function run()
  {
    if ( \count((array)$this->obj) === 0 ){
      header('HTTP/1.0 404 Not Found');
      exit();
    }

    if ( $this->mode === 'cli' ){
      if ( !headers_sent() && !$this->obj->content ){
        exit('No output...');
      }
      if ( $this->obj->content ){
        echo $this->obj->content;
      }
      @ob_end_flush();
      exit();
    }

    if ( isset($this->obj->prescript) ){
      if ( empty($this->obj->prescript) ){
        unset($this->obj->prescript);
      }
      else if ( !BBN_IS_DEV ){
        try{
          $tmp = \JShrink\Minifier::minify($this->obj->prescript);
        }
        catch ( \RuntimeException $e ){
          \bbn\x::log($this->obj->prescript, 'js_shrink');
        }
        if ( $tmp ){
          $this->obj->prescript = $tmp;
        }
      }
    }
    if ( isset($this->obj->script) ){
      if ( empty($this->obj->script) ){
        unset($this->obj->script);
      }
      else if ( !BBN_IS_DEV ){
        try{
          $tmp = \JShrink\Minifier::minify($this->obj->script);
        }
        catch ( \RuntimeException $e ){
          \bbn\x::log($this->obj->script, 'js_shrink');
        }
        if ( $tmp ){
          $this->obj->script = $tmp;
        }

      }
    }
    if ( isset($this->obj->postscript) ){
      if ( empty($this->obj->postscript) ){
        unset($this->obj->postscript);
      }
      else if ( !BBN_IS_DEV ){
        try{
          $tmp = \JShrink\Minifier::minify($this->obj->postscript);
        }
        catch ( \RuntimeException $e ){
          \bbn\x::log($this->obj->postscript, 'js_shrink');
        }
        if ( $tmp ){
          $this->obj->postscript = $tmp;
        }
      }
    }
    if ( empty($this->obj->content) || ( ($this->mode === 'file') || ($this->mode === 'image') ) ){
      if (!empty($this->obj->file)){
        if (\is_string($this->obj->file) && is_file($this->obj->file)){
          $this->obj->file = new bbn\file($this->obj->file);
        }
        if (\is_object($this->obj->file) &&
          method_exists($this->obj->file, 'download') &&
          method_exists($this->obj->file, 'test') &&
          $this->obj->file->test()
        ){
          $this->mode = 'file';
        }
      }
      else if (!empty($this->obj->img)){
        if (\is_string($this->obj->img) && is_file($this->obj->img)){
          $this->obj->img = new bbn\file\image($this->obj->img);
        }
        if (\is_object($this->obj->img) &&
          method_exists($this->obj->img, 'display') &&
          method_exists($this->obj->img, 'test') &&
          $this->obj->img->test()
        ){
          $this->mode = 'image';
        }
      }
    }
    switch ( $this->mode ){
      case 'public':
      case 'json':
      case 'js':
      case 'css':
      case 'doc':
      case 'html':
        if ( !ob_start("ob_gzhandler" ) ){
          ob_start();
        }
        else{
          header('Content-Encoding: gzip');
        }
        break;
      default:
        ob_start();
    }
    if ( (empty($this->obj->content) && empty($this->obj->file) && empty($this->obj->img) && ($this->mode !==
          'public')) ||
      (($this->mode === 'public') && empty($this->obj)) ){
      $this->mode = '';
    }
    else if ( !empty($this->obj->content) && !empty($this->obj->help) ){
      $Parsedown = new \Parsedown();
      $this->obj->help = $Parsedown->text($this->obj->help);
    }
    switch ( $this->mode ){

      case 'public':
        header('Content-type: application/json; charset=utf-8');
        echo json_encode($this->obj);
        break;

      case 'js':
        header('Content-type: application/javascript; charset=utf-8');
        echo $this->obj->content;
        break;

      case 'css':
        header('Content-type: text/css; charset=utf-8');
        echo $this->obj->content;
        break;

      case 'text':
        header('Content-type: text/plain; charset=utf-8');
        echo $this->obj->content;
        break;

      case 'xml':
        header('Content-type: text/xml; charset=utf-8');
        echo $this->obj->content;
        break;

      case 'image':
        if ( isset($this->obj->img) && \is_object($this->obj->img) ){
          $this->obj->img->display();
        }
        else{
          $this->log("Impossible to display the following image: ".$this->obj->img->name);
          header('HTTP/1.0 404 Not Found');

        }
        break;

      case 'file':
        if ( isset($this->obj->file) && \is_object($this->obj->file) && method_exists($this->obj->file, 'download') ){
          $this->obj->file->download();
        }
        else{
          $this->log("Impossible to display the following controller", $this);
          header('HTTP/1.0 404 Not Found');
          exit();
        }
        break;

      default:
        header('Content-type: text/html; charset=utf-8');
        echo isset($this->obj->content) ? $this->obj->content : '';

    }
  }
758693
public function start()
    {
        if ($this->_started) {
            return true;
        }

        if ($this->_isCLI) {
            $_SESSION = [];
            $this->id('cli');

            return $this->_started = true;
        }

        if (session_status() === \PHP_SESSION_ACTIVE) {
            throw new RuntimeException('Session was already started');
        }

        if (ini_get('session.use_cookies') && headers_sent($file, $line)) {
            return false;
        }

        if (!session_start()) {
            throw new RuntimeException('Could not start the session');
        }

        $this->_started = true;

        if ($this->_timedOut()) {
            $this->destroy();

            return $this->start();
        }

        return $this->_started;
    }
539206
public function run()
    {

        // register a shutdown handler for controlled shutdown
        register_shutdown_function(array(&$this, 'shutdown'));

        // we need the autloader again
        require SERVER_AUTOLOADER;

        // create a reference to the application server instance
        $applicationServer = $this->applicationServer;

        // initialize the event loop and the socket server
        $loop = \React\EventLoop\Factory::create();
        $socket = new \React\Socket\Server($loop);

        // wait for connections
        $socket->on('connection', function ($conn) use ($applicationServer) {
            // wait for user input => usually a command
            $conn->on('data', function ($data) use ($conn, $applicationServer) {
                try {
                    // extract command name and parameters
                    $params = Arguments::split($data);
                    $commandName = array_shift($params);

                    try {
                        // initialize and execute the command
                        $command = CommandFactory::factory($commandName, array($conn, $applicationServer));
                        $command->execute($params);

                    } catch (\ReflectionException $re) {
                        $conn->write(sprintf("Unknown command %sERROR\n", $commandName));
                    }

                } catch (\Exception $e) {
                    $conn->write("{$e->__toString()}ERROR\n");
                }
            });
        });

        // listen to the management socket
        $socket->listen($this->getPort(), $this->getAddress());

        // start the event loop and the socket server, but disable warnings as some React warnings cannot (or won't) be dealt with.
        // Specifically the warning if a client disconnects unexpectedly or does not even connect to begin with ("Interrupted system call") is unevitable
        // @see https://github.com/reactphp/react/pull/297
        // @see https://github.com/reactphp/react/issues/296
        // @see http://php.net/manual/de/function.stream-select.php
        $currentReportingLevel = error_reporting();
        error_reporting(E_ALL ^ E_WARNING);
        $loop->run();
        error_reporting($currentReportingLevel);
    }
1056112
public function startAction()
  {
    $this->setNoRender();

    /* grab user parameters from $_REQUEST array */
    $sid = TeamSpeak3_Helper_Uri::getUserParam("id", 0);

    try
    {
      /* start server */
      $this->ts3->serverStart($sid);

      /* save custom ok mesage */
      $this->setLastEvent("The virtual server (ID " . $sid . ") has been started.");
    }
    catch(Exception $e)
    {
      /* save catched error mesage */
      $this->setLastEvent($e->getMessage(), TRUE);
    }

    /* goto indexAction() */
    $this->redirect("server");
  }
436718
public function restart()
    {
        if (count($this->tasks) == 0)
            throw new \Exception("There are no tasks defined - can not restart");

        $this->stop();

        do {
            sleep(1);
        } while ($this->getPid() !== false);

        $this->start();
    }
685247
public function daemonRunCommand(): void
    {
        $ret = ProcessUtil::daemonRun(function ($pid){
            $this->output->info("will running background by new process: $pid");
        });

        if ($ret === 0) {
            $this->output->liteError('current env is not support process create.');
        }
    }
737565
def start_server(self):
        """"""
        if self.server is None:
            self.port = select_port(default_port=self.DEFAULT_PORT)
            self.set_home_url('http://localhost:%d/' % self.port)
        elif self.server.isRunning():
            self.server.server_started.disconnect(self.initialize_continued)
            self.server.quit()
        self.server = PydocServer(port=self.port)
        self.server.server_started.connect(self.initialize_continued)
        self.server.start()
781583
final public function run()
    {
        try {
            $response = $this->execute();
            $statusCode = 0;
            if ($response instanceof
                \WebServCo\Framework\Interfaces\ResponseInterface) {
                $statusCode = $response->send();
            }
            $this->shutdown(null, true, Framework::isCli() ? $statusCode : 0);
        } catch (\Throwable $e) { // php7
            $this->shutdown($e, true);
        } catch (\Exception $e) { // php5
            $this->shutdown($e, true);
        }
    }
1231931
public function run()
    {
        if (!$this->started) {
            $this->start();
        }

        if (function_exists('pcntl_signal')) {
            // PHP 7.1 allows async signals
            if (function_exists('pcntl_async_signals')) {
                pcntl_async_signals(true);
            } else {
                declare(ticks = 1);
            }
            pcntl_signal(SIGTERM, array($this, 'shutdown'));
            pcntl_signal(SIGINT, array($this, 'shutdown'));
            pcntl_signal(SIGQUIT, array($this, 'shutdown'));
        }

        register_shutdown_function(array($this, 'close'));

        while (true) {
            if ($this->shutdown) {
                $this->log('Shutting down listener on <pop>'.$this.'</pop>', Logger::INFO);
                break;
            }

            $read = array($this->socket);
            foreach ($this->clients as &$client) {
                $read[] = $client->getSocket();
            }

            // Set up a blocking call to socket_select
            $write = $except = null;
            if (($changed_sockets = @socket_select($read, $write, $except, $this->tv_sec)) < 1) {
                // $this->log('Waiting for socket update', self::LOG_VERBOSE);
                continue;
            }

            // Handle new Connections
            if (in_array($this->socket, $read)) {
                if (count($this->clients) >= $this->max_clients) {
                    $this->log('New client trying to connect but maximum <pop>'.$this->max_clients.'</pop> clients already connected', Logger::INFO);

                    $client = new Client($this->socket);
                    $this->send($client, '{"ok":0,"message":"Could not connect, hit max number of connections"}');
                    $client->disconnect();
                    continue;
                } else {
                    $this->clients[] = $client = new Client($this->socket);

                    $this->log('New client connected: <pop>'.$client.'</pop>', Logger::INFO);

                    $this->fire(self::CLIENT_CONNECT, $client);
                }
            }

            // Handle input for each client
            foreach ($this->clients as $i => $client) {
                if (in_array($client->getSocket(), $read)) {
                    $data = @socket_read($client->getSocket(), $this->max_read);

                    if ($data === false) {
                        $this->disconnect($client);
                        continue;
                    }

                    // Remove any control characters
                    $data = preg_replace('/[\x00-\x1F\x7F]/', '', trim($data));

                    if (empty($data)) {
                        // Send a null byte to flush
                        $this->send($client, "\0");
                    } else {
                        $this->log(sprintf('Received "<comment>%s</comment>" from <pop>%s</pop>', $data, $client), Logger::INFO);
                        $this->fire(self::CLIENT_RECEIVE, $client, $data);
                    }
                }
            }
        }
    }
47989
def startserver(self, hostname="localhost", port=8080,
                    daemon=False, handle_sigint=True):
        """"""
        if daemon:
            print("Sorry daemon server not supported just yet.")
            # TODO start as daemon similar to bitcoind
        else:
            print("Starting %s json-rpc service at http://%s:%s" % (
                self.__class__.__name__, hostname, port
            ))
            self._http_server = HTTPServer(
                server_address=(hostname, int(port)),
                RequestHandlerClass=self.get_http_request_handler()
            )

            if handle_sigint:
                def sigint_handler(signum, frame):
                    self._post_shutdown()
                    sys.exit(0)
                signal.signal(signal.SIGINT, sigint_handler)
            self._http_server.serve_forever()
92679
protected function start()
    {
        $pid = $this->getMasterPid();

        if ($this->isRunning($pid)) {
            $this->output->writeln('<error>swoole http server process is already running.</error>');
            return;
        }

        $this->output->writeln('Starting swoole http server...');

        /** @var Swoole $swoole */
        $swoole = $this->app->make(Swoole::class);

        if ($this->config['auto_reload']) {
            //热更新
            /** @var \Swoole\Server $server */
            $server = $this->app->make(\think\swoole\facade\Server::class);

            $server->addProcess($this->getHotReloadProcess($server, (int) $this->config['auto_reload']));
        }

        $host = $this->config['server']['host'];
        $port = $this->config['server']['port'];

        $this->output->writeln("Swoole http server started: <http://{$host}:{$port}>");
        $this->output->writeln('You can exit with <info>`CTRL-C`</info>');

        $swoole->run();
    }
656811
protected function reload()
    {
        $pid = $this->getMasterPid();

        if (!$this->isRunning($pid)) {
            $this->output->writeln('<error>no swoole http server process running.</error>');
            return;
        }

        $this->output->writeln('Reloading swoole http server...');

        $isRunning = $this->killProcess($pid, SIGUSR1);

        if (!$isRunning) {
            $this->output->error('> failure');

            return;
        }

        $this->output->writeln('> success');
    }
675020
public function run()
    {
        foreach ($this->getSteps() as $step) {
            $this->logger->info('Starting "'.$step->getTitle().'"');

            foreach ($this->getServersForStep($step) as $server) {
                if ($step->isMandatory()) {
                    $server->runCommands();
                    $this->logger->info('Finished "'.$step->getTitle().'" on "'.$server->getTitle().'"');
                } else {
                    try {
                        $server->runCommands();
                        $this->logger->info('Finished "'.$step->getTitle().'" on "'.$server->getTitle().'"');
                    } catch (\Exception $e) {
                        $this->logger->info('Failed to run "'.$step->getTitle().'" on "'.$server->getTitle().'"');
                    }
                }
            }
        }
    }
234640
protected void startServerCommandListener() {
        String uuid = systemBundleCtx.getProperty("org.osgi.framework.uuid");
        sc = new ServerCommandListener(config, uuid, this);
        sc.startListening();
    }
886772
public function runInBackgroundCommand(): void
    {
        $script = '<?php print_r($_SERVER); ?>';
        $ret = Sys::execInBackground("php $script");

        if ($ret === false) {
            $this->output->liteError('current env is not support process create.');
        }
    }