From e87db889e939cedcc7fe73425940615ef84ce09a Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 21 Dec 2019 21:01:38 -0800 Subject: [PATCH] Fix server data not updating correctly on daemon --- .../Servers/BuildModificationService.php | 33 ++++++++----------- .../ServerConfigurationStructureService.php | 9 ++--- .../Servers/StartupModificationService.php | 33 +++++++++---------- 3 files changed, 33 insertions(+), 42 deletions(-) diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index 4da6e7c4f..13400ee9a 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Services\Servers; +use Illuminate\Support\Arr; use Pterodactyl\Models\Server; use GuzzleHttp\Exception\RequestException; use Illuminate\Database\ConnectionInterface; @@ -34,16 +35,23 @@ class BuildModificationService */ private $repository; + /** + * @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService + */ + private $structureService; + /** * BuildModificationService constructor. * * @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository + * @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService * @param \Illuminate\Database\ConnectionInterface $connection * @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository */ public function __construct( AllocationRepositoryInterface $allocationRepository, + ServerConfigurationStructureService $structureService, ConnectionInterface $connection, DaemonServerRepository $daemonServerRepository, ServerRepositoryInterface $repository @@ -52,6 +60,7 @@ class BuildModificationService $this->daemonServerRepository = $daemonServerRepository; $this->connection = $connection; $this->repository = $repository; + $this->structureService = $structureService; } /** @@ -95,28 +104,12 @@ class BuildModificationService 'allocation_limit' => array_get($data, 'allocation_limit'), ]); - $updateData = [ - 'allocations' => [ - 'default' => [ - 'ip' => $server->allocation->ip, - 'port' => $server->allocation->port, - ], - 'mappings' => $server->getAllocationMappings(), - ], - 'build' => [ - 'memory' => $server->memory, - 'swap' => $server->swap, - 'io' => $server->io, - 'cpu' => $server->cpu, - 'disk' => $server->disk, - ], - 'container' => [ - 'oom_disabled' => $server->oom_disabled, - ], - ]; + $updateData = $this->structureService->handle($server); try { - $this->daemonServerRepository->setServer($server)->update($updateData); + $this->daemonServerRepository->setServer($server)->update( + Arr::only($updateData, ['allocations', 'build', 'container']) + ); $this->connection->commit(); } catch (RequestException $exception) { throw new DaemonConnectionException($exception); diff --git a/app/Services/Servers/ServerConfigurationStructureService.php b/app/Services/Servers/ServerConfigurationStructureService.php index 779eac2b0..9984e3a98 100644 --- a/app/Services/Servers/ServerConfigurationStructureService.php +++ b/app/Services/Servers/ServerConfigurationStructureService.php @@ -75,12 +75,13 @@ class ServerConfigurationStructureService 'uuid' => $server->uuid, 'suspended' => (bool) $server->suspended, 'environment' => $this->environment->handle($server), + 'invocation' => $server->startup, 'build' => [ - 'memory' => $server->memory, + 'memory_limit' => $server->memory, 'swap' => $server->swap, - 'io' => $server->io, - 'cpu' => $server->cpu, - 'disk' => $server->disk, + 'io_weight' => $server->io, + 'cpu_limit' => $server->cpu, + 'disk_space' => $server->disk, ], 'service' => [ 'egg' => $server->egg->uuid, diff --git a/app/Services/Servers/StartupModificationService.php b/app/Services/Servers/StartupModificationService.php index 8cbc4ab2c..ebcd58923 100644 --- a/app/Services/Servers/StartupModificationService.php +++ b/app/Services/Servers/StartupModificationService.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Services\Servers; +use Illuminate\Support\Arr; use Pterodactyl\Models\User; use Pterodactyl\Models\Server; use GuzzleHttp\Exception\RequestException; @@ -52,6 +53,11 @@ class StartupModificationService */ private $daemonServerRepository; + /** + * @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService + */ + private $structureService; + /** * StartupModificationService constructor. * @@ -60,6 +66,7 @@ class StartupModificationService * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $eggRepository * @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository + * @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService * @param \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface $serverVariableRepository * @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService */ @@ -69,6 +76,7 @@ class StartupModificationService EggRepositoryInterface $eggRepository, EnvironmentService $environmentService, ServerRepositoryInterface $repository, + ServerConfigurationStructureService $structureService, ServerVariableRepositoryInterface $serverVariableRepository, VariableValidatorService $validatorService ) { @@ -79,6 +87,7 @@ class StartupModificationService $this->serverVariableRepository = $serverVariableRepository; $this->validatorService = $validatorService; $this->daemonServerRepository = $daemonServerRepository; + $this->structureService = $structureService; } /** @@ -110,19 +119,16 @@ class StartupModificationService }); } - $daemonData = []; if ($this->isUserLevel(User::USER_LEVEL_ADMIN)) { - $this->updateAdministrativeSettings($data, $server, $daemonData); + $this->updateAdministrativeSettings($data, $server); } - $daemonData = array_merge_recursive($daemonData, [ - 'build' => [ - 'env|overwrite' => $this->environmentService->handle($server), - ], - ]); + $updateData = $this->structureService->handle($server); try { - $this->daemonServerRepository->setServer($server)->update($daemonData); + $this->daemonServerRepository->setServer($server)->update( + Arr::only($updateData, ['environment', 'invocation', 'service']) + ); } catch (RequestException $exception) { $this->connection->rollBack(); throw new DaemonConnectionException($exception); @@ -138,12 +144,11 @@ class StartupModificationService * * @param array $data * @param \Pterodactyl\Models\Server $server - * @param array $daemonData * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ - private function updateAdministrativeSettings(array $data, Server &$server, array &$daemonData) + private function updateAdministrativeSettings(array $data, Server &$server) { if ( is_digit(array_get($data, 'egg_id')) @@ -163,13 +168,5 @@ class StartupModificationService 'skip_scripts' => array_get($data, 'skip_scripts') ?? isset($data['skip_scripts']), 'image' => array_get($data, 'docker_image', $server->image), ]); - - $daemonData = array_merge($daemonData, [ - 'build' => ['image' => $server->image], - 'service' => array_merge( - $this->repository->getDaemonServiceData($server, true), - ['skip_scripts' => $server->skip_scripts] - ), - ]); } }