Fix server data not updating correctly on daemon

This commit is contained in:
Dane Everitt 2019-12-21 21:01:38 -08:00
parent 3e915e526b
commit e87db889e9
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 33 additions and 42 deletions

View file

@ -2,6 +2,7 @@
namespace Pterodactyl\Services\Servers; namespace Pterodactyl\Services\Servers;
use Illuminate\Support\Arr;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
@ -34,16 +35,23 @@ class BuildModificationService
*/ */
private $repository; private $repository;
/**
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
*/
private $structureService;
/** /**
* BuildModificationService constructor. * BuildModificationService constructor.
* *
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository * @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService
* @param \Illuminate\Database\ConnectionInterface $connection * @param \Illuminate\Database\ConnectionInterface $connection
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository * @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
*/ */
public function __construct( public function __construct(
AllocationRepositoryInterface $allocationRepository, AllocationRepositoryInterface $allocationRepository,
ServerConfigurationStructureService $structureService,
ConnectionInterface $connection, ConnectionInterface $connection,
DaemonServerRepository $daemonServerRepository, DaemonServerRepository $daemonServerRepository,
ServerRepositoryInterface $repository ServerRepositoryInterface $repository
@ -52,6 +60,7 @@ class BuildModificationService
$this->daemonServerRepository = $daemonServerRepository; $this->daemonServerRepository = $daemonServerRepository;
$this->connection = $connection; $this->connection = $connection;
$this->repository = $repository; $this->repository = $repository;
$this->structureService = $structureService;
} }
/** /**
@ -95,28 +104,12 @@ class BuildModificationService
'allocation_limit' => array_get($data, 'allocation_limit'), 'allocation_limit' => array_get($data, 'allocation_limit'),
]); ]);
$updateData = [ $updateData = $this->structureService->handle($server);
'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,
],
];
try { try {
$this->daemonServerRepository->setServer($server)->update($updateData); $this->daemonServerRepository->setServer($server)->update(
Arr::only($updateData, ['allocations', 'build', 'container'])
);
$this->connection->commit(); $this->connection->commit();
} catch (RequestException $exception) { } catch (RequestException $exception) {
throw new DaemonConnectionException($exception); throw new DaemonConnectionException($exception);

View file

@ -75,12 +75,13 @@ class ServerConfigurationStructureService
'uuid' => $server->uuid, 'uuid' => $server->uuid,
'suspended' => (bool) $server->suspended, 'suspended' => (bool) $server->suspended,
'environment' => $this->environment->handle($server), 'environment' => $this->environment->handle($server),
'invocation' => $server->startup,
'build' => [ 'build' => [
'memory' => $server->memory, 'memory_limit' => $server->memory,
'swap' => $server->swap, 'swap' => $server->swap,
'io' => $server->io, 'io_weight' => $server->io,
'cpu' => $server->cpu, 'cpu_limit' => $server->cpu,
'disk' => $server->disk, 'disk_space' => $server->disk,
], ],
'service' => [ 'service' => [
'egg' => $server->egg->uuid, 'egg' => $server->egg->uuid,

View file

@ -2,6 +2,7 @@
namespace Pterodactyl\Services\Servers; namespace Pterodactyl\Services\Servers;
use Illuminate\Support\Arr;
use Pterodactyl\Models\User; use Pterodactyl\Models\User;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
@ -52,6 +53,11 @@ class StartupModificationService
*/ */
private $daemonServerRepository; private $daemonServerRepository;
/**
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
*/
private $structureService;
/** /**
* StartupModificationService constructor. * StartupModificationService constructor.
* *
@ -60,6 +66,7 @@ class StartupModificationService
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $eggRepository * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $eggRepository
* @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService * @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService
* @param \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface $serverVariableRepository * @param \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface $serverVariableRepository
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService * @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
*/ */
@ -69,6 +76,7 @@ class StartupModificationService
EggRepositoryInterface $eggRepository, EggRepositoryInterface $eggRepository,
EnvironmentService $environmentService, EnvironmentService $environmentService,
ServerRepositoryInterface $repository, ServerRepositoryInterface $repository,
ServerConfigurationStructureService $structureService,
ServerVariableRepositoryInterface $serverVariableRepository, ServerVariableRepositoryInterface $serverVariableRepository,
VariableValidatorService $validatorService VariableValidatorService $validatorService
) { ) {
@ -79,6 +87,7 @@ class StartupModificationService
$this->serverVariableRepository = $serverVariableRepository; $this->serverVariableRepository = $serverVariableRepository;
$this->validatorService = $validatorService; $this->validatorService = $validatorService;
$this->daemonServerRepository = $daemonServerRepository; $this->daemonServerRepository = $daemonServerRepository;
$this->structureService = $structureService;
} }
/** /**
@ -110,19 +119,16 @@ class StartupModificationService
}); });
} }
$daemonData = [];
if ($this->isUserLevel(User::USER_LEVEL_ADMIN)) { if ($this->isUserLevel(User::USER_LEVEL_ADMIN)) {
$this->updateAdministrativeSettings($data, $server, $daemonData); $this->updateAdministrativeSettings($data, $server);
} }
$daemonData = array_merge_recursive($daemonData, [ $updateData = $this->structureService->handle($server);
'build' => [
'env|overwrite' => $this->environmentService->handle($server),
],
]);
try { try {
$this->daemonServerRepository->setServer($server)->update($daemonData); $this->daemonServerRepository->setServer($server)->update(
Arr::only($updateData, ['environment', 'invocation', 'service'])
);
} catch (RequestException $exception) { } catch (RequestException $exception) {
$this->connection->rollBack(); $this->connection->rollBack();
throw new DaemonConnectionException($exception); throw new DaemonConnectionException($exception);
@ -138,12 +144,11 @@ class StartupModificationService
* *
* @param array $data * @param array $data
* @param \Pterodactyl\Models\Server $server * @param \Pterodactyl\Models\Server $server
* @param array $daemonData
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
private function updateAdministrativeSettings(array $data, Server &$server, array &$daemonData) private function updateAdministrativeSettings(array $data, Server &$server)
{ {
if ( if (
is_digit(array_get($data, 'egg_id')) is_digit(array_get($data, 'egg_id'))
@ -163,13 +168,5 @@ class StartupModificationService
'skip_scripts' => array_get($data, 'skip_scripts') ?? isset($data['skip_scripts']), 'skip_scripts' => array_get($data, 'skip_scripts') ?? isset($data['skip_scripts']),
'image' => array_get($data, 'docker_image', $server->image), '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]
),
]);
} }
} }