Fix server data not updating correctly on daemon
This commit is contained in:
parent
3e915e526b
commit
e87db889e9
3 changed files with 33 additions and 42 deletions
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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]
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue