From 7355798e7776bdb00d121a7b6b392f0f40ae32be Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 3 Jun 2022 18:34:54 +0100 Subject: [PATCH] Exit with error code if the server failed to start this ensures that external tools such as start.cmd actually see an error if there is one --- src/Server.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Server.php b/src/Server.php index efc13c027..df2d1ebbf 100644 --- a/src/Server.php +++ b/src/Server.php @@ -861,7 +861,7 @@ class Server{ $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error3())); $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error4("settings.enable-dev-builds"))); $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error5("https://github.com/pmmp/PocketMine-MP/releases"))); - $this->forceShutdown(); + $this->forceShutdownExit(); return; } @@ -976,7 +976,7 @@ class Server{ $pluginGraylist = PluginGraylist::fromArray(yaml_parse(file_get_contents($graylistFile))); }catch(\InvalidArgumentException $e){ $this->logger->emergency("Failed to load $graylistFile: " . $e->getMessage()); - $this->forceShutdown(); + $this->forceShutdownExit(); return; } $this->pluginManager = new PluginManager($this, $this->configGroup->getPropertyBool("plugins.legacy-data-dir", true) ? null : Path::join($this->getDataPath(), "plugin_data"), $pluginGraylist); @@ -1007,28 +1007,28 @@ class Server{ $this->pluginManager->loadPlugins($this->pluginPath, $loadErrorCount); if($loadErrorCount > 0){ $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_plugin_someLoadErrors())); - $this->forceShutdown(); + $this->forceShutdownExit(); return; } if(!$this->enablePlugins(PluginEnableOrder::STARTUP())){ $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_plugin_someEnableErrors())); - $this->forceShutdown(); + $this->forceShutdownExit(); return; } if(!$this->startupPrepareWorlds()){ - $this->forceShutdown(); + $this->forceShutdownExit(); return; } if(!$this->enablePlugins(PluginEnableOrder::POSTWORLD())){ $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_plugin_someEnableErrors())); - $this->forceShutdown(); + $this->forceShutdownExit(); return; } if(!$this->startupPrepareNetworkInterfaces()){ - $this->forceShutdown(); + $this->forceShutdownExit(); return; } @@ -1456,6 +1456,11 @@ class Server{ } } + private function forceShutdownExit() : void{ + $this->forceShutdown(); + Process::kill(Process::pid(), true); + } + public function forceShutdown() : void{ if($this->hasStopped){ return;