diff --git a/app/Filament/Resources/ServerResource/Pages/CreateServer.php b/app/Filament/Resources/ServerResource/Pages/CreateServer.php index 852b1e7d1..b2e2a0705 100644 --- a/app/Filament/Resources/ServerResource/Pages/CreateServer.php +++ b/app/Filament/Resources/ServerResource/Pages/CreateServer.php @@ -610,7 +610,7 @@ class CreateServer extends CreateRecord ->columns(4) ->columnSpanFull() ->schema([ - Forms\Components\ToggleButtons::make('oom_disabled') + Forms\Components\ToggleButtons::make('oom_killer') ->label('OOM Killer') ->inlineLabel()->inline() ->default(false) diff --git a/app/Filament/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Resources/ServerResource/Pages/EditServer.php index 735adf657..3fed72f3c 100644 --- a/app/Filament/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Resources/ServerResource/Pages/EditServer.php @@ -432,7 +432,7 @@ class EditServer extends EditRecord ->columns(4) ->columnSpanFull() ->schema([ - Forms\Components\ToggleButtons::make('oom_disabled') + Forms\Components\ToggleButtons::make('oom_killer') ->label('OOM Killer')->inlineLabel()->inline() ->columnSpan(2) ->options([ diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 9aa0af24e..5a2b8074f 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -126,7 +126,7 @@ class ServersController extends Controller $this->buildModificationService->handle($server, $request->only([ 'allocation_id', 'add_allocations', 'remove_allocations', 'memory', 'swap', 'io', 'cpu', 'threads', 'disk', - 'database_limit', 'allocation_limit', 'backup_limit', 'oom_disabled', + 'database_limit', 'allocation_limit', 'backup_limit', 'oom_killer', ])); } catch (DataValidationException $exception) { throw new ValidationException($exception->getValidator()); diff --git a/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php b/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php index c1919255f..d3343e7a5 100644 --- a/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php +++ b/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php @@ -32,7 +32,7 @@ class StoreServerRequest extends ApplicationApiRequest 'startup' => $rules['startup'], 'environment' => 'present|array', 'skip_scripts' => 'sometimes|boolean', - 'oom_disabled' => 'sometimes|boolean', + 'oom_killer' => 'sometimes|boolean', // Resource limitations 'limits' => 'required|array', @@ -94,7 +94,7 @@ class StoreServerRequest extends ApplicationApiRequest 'database_limit' => array_get($data, 'feature_limits.databases'), 'allocation_limit' => array_get($data, 'feature_limits.allocations'), 'backup_limit' => array_get($data, 'feature_limits.backups'), - 'oom_disabled' => array_get($data, 'oom_disabled'), + 'oom_killer' => array_get($data, 'oom_killer'), ]; } diff --git a/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php b/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php index f9b0fa20e..7b0fcad10 100644 --- a/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php +++ b/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php @@ -16,7 +16,7 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest return [ 'allocation' => $rules['allocation_id'], - 'oom_disabled' => $rules['oom_disabled'], + 'oom_killer' => $rules['oom_killer'], 'limits' => 'sometimes|array', 'limits.memory' => $this->requiredToOptional('memory', $rules['memory'], true), diff --git a/app/Models/Server.php b/app/Models/Server.php index a044709c2..73d2b64fc 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -35,7 +35,7 @@ use App\Exceptions\Http\Server\ServerStateConflictException; * @property int $io * @property int $cpu * @property string|null $threads - * @property bool $oom_disabled + * @property bool $oom_killer * @property int $allocation_id * @property int $egg_id * @property string $startup @@ -90,7 +90,7 @@ use App\Exceptions\Http\Server\ServerStateConflictException; * @method static \Illuminate\Database\Eloquent\Builder|Server whereMemory($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereNodeId($value) - * @method static \Illuminate\Database\Eloquent\Builder|Server whereOomDisabled($value) + * @method static \Illuminate\Database\Eloquent\Builder|Server whereOomKiller($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereOwnerId($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereSkipScripts($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereStartup($value) @@ -124,7 +124,7 @@ class Server extends Model */ protected $attributes = [ 'status' => ServerState::Installing, - 'oom_disabled' => true, + 'oom_killer' => false, 'installed_at' => null, ]; @@ -150,7 +150,7 @@ class Server extends Model 'io' => 'required|numeric|between:0,1000', 'cpu' => 'required|numeric|min:0', 'threads' => 'nullable|regex:/^[0-9-,]+$/', - 'oom_disabled' => 'sometimes|boolean', + 'oom_killer' => 'sometimes|boolean', 'disk' => 'required|numeric|min:0', 'allocation_id' => 'required|bail|unique:servers|exists:allocations,id', 'egg_id' => 'required|exists:eggs,id', @@ -174,7 +174,7 @@ class Server extends Model 'disk' => 'integer', 'io' => 'integer', 'cpu' => 'integer', - 'oom_disabled' => 'boolean', + 'oom_killer' => 'boolean', 'allocation_id' => 'integer', 'egg_id' => 'integer', 'database_limit' => 'integer', diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index 2b73c138e..2f2a0bda5 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -41,7 +41,7 @@ class BuildModificationService } // If any of these values are passed through in the data array go ahead and set them correctly on the server model. - $merge = Arr::only($data, ['oom_disabled', 'memory', 'swap', 'io', 'cpu', 'threads', 'disk', 'allocation_id']); + $merge = Arr::only($data, ['oom_killer', 'memory', 'swap', 'io', 'cpu', 'threads', 'disk', 'allocation_id']); $server->forceFill(array_merge($merge, [ 'database_limit' => Arr::get($data, 'database_limit', 0) ?? null, diff --git a/app/Services/Servers/ServerConfigurationStructureService.php b/app/Services/Servers/ServerConfigurationStructureService.php index 8096a64ce..7b06aca36 100644 --- a/app/Services/Servers/ServerConfigurationStructureService.php +++ b/app/Services/Servers/ServerConfigurationStructureService.php @@ -59,14 +59,12 @@ class ServerConfigurationStructureService 'cpu_limit' => $server->cpu, 'threads' => $server->threads, 'disk_space' => $server->disk, - 'oom_disabled' => $server->oom_disabled, + // This field is deprecated — use "oom_killer". + 'oom_disabled' => !$server->oom_killer, + 'oom_killer' => !$server->oom_killer, ], 'container' => [ 'image' => $server->image, - // This field is deprecated — use the value in the "build" block. - // - // TODO: remove this key in V2. - 'oom_disabled' => $server->oom_disabled, 'requires_rebuild' => false, ], 'allocations' => [ @@ -110,7 +108,7 @@ class ServerConfigurationStructureService return $item->pluck('port'); })->toArray(), 'env' => $this->environment->handle($server), - 'oom_disabled' => $server->oom_disabled, + 'oom_disabled' => !$server->oom_killer, 'memory' => (int) $server->memory, 'swap' => (int) $server->swap, 'io' => (int) $server->io, diff --git a/app/Services/Servers/ServerCreationService.php b/app/Services/Servers/ServerCreationService.php index b49cc74ac..7831d1a40 100644 --- a/app/Services/Servers/ServerCreationService.php +++ b/app/Services/Servers/ServerCreationService.php @@ -142,7 +142,7 @@ class ServerCreationService 'io' => Arr::get($data, 'io'), 'cpu' => Arr::get($data, 'cpu'), 'threads' => Arr::get($data, 'threads'), - 'oom_disabled' => Arr::get($data, 'oom_disabled') ?? true, + 'oom_killer' => Arr::get($data, 'oom_killer') ?? false, 'allocation_id' => Arr::get($data, 'allocation_id'), 'egg_id' => Arr::get($data, 'egg_id'), 'startup' => Arr::get($data, 'startup'), diff --git a/app/Transformers/Api/Application/ServerTransformer.php b/app/Transformers/Api/Application/ServerTransformer.php index b315422c5..90836cc24 100644 --- a/app/Transformers/Api/Application/ServerTransformer.php +++ b/app/Transformers/Api/Application/ServerTransformer.php @@ -65,7 +65,9 @@ class ServerTransformer extends BaseTransformer 'io' => $server->io, 'cpu' => $server->cpu, 'threads' => $server->threads, - 'oom_disabled' => $server->oom_disabled, + // This field is deprecated, please use "oom_killer". + 'oom_disabled' => !$server->oom_killer, + 'oom_killer' => $server->oom_killer, ], 'feature_limits' => [ 'databases' => $server->database_limit, diff --git a/app/Transformers/Api/Client/ServerTransformer.php b/app/Transformers/Api/Client/ServerTransformer.php index aece52bd5..686a8e237 100644 --- a/app/Transformers/Api/Client/ServerTransformer.php +++ b/app/Transformers/Api/Client/ServerTransformer.php @@ -56,7 +56,9 @@ class ServerTransformer extends BaseClientTransformer 'io' => $server->io, 'cpu' => $server->cpu, 'threads' => $server->threads, - 'oom_disabled' => $server->oom_disabled, + // This field is deprecated, please use "oom_killer". + 'oom_disabled' => !$server->oom_killer, + 'oom_killer' => $server->oom_killer, ], 'invocation' => $service->handle($server, !$user->can(Permission::ACTION_STARTUP_READ, $server)), 'docker_image' => $server->image, diff --git a/database/Factories/ServerFactory.php b/database/Factories/ServerFactory.php index 3bd7931b3..e0ced8de5 100644 --- a/database/Factories/ServerFactory.php +++ b/database/Factories/ServerFactory.php @@ -35,7 +35,7 @@ class ServerFactory extends Factory 'io' => 500, 'cpu' => 0, 'threads' => null, - 'oom_disabled' => 0, + 'oom_killer' => false, 'startup' => '/bin/bash echo "hello world"', 'image' => 'foo/bar:latest', 'allocation_limit' => null, diff --git a/database/migrations/2024_05_08_094823_rename_oom_disabled_column_to_oom_killer.php b/database/migrations/2024_05_08_094823_rename_oom_disabled_column_to_oom_killer.php new file mode 100644 index 000000000..4e941db28 --- /dev/null +++ b/database/migrations/2024_05_08_094823_rename_oom_disabled_column_to_oom_killer.php @@ -0,0 +1,45 @@ +tinyInteger('oom_killer')->unsigned()->default(0)->after('oom_disabled'); + }); + + DB::table('servers')->select(['id', 'oom_disabled'])->cursor()->each(function ($server) { + DB::table('servers')->where('id', $server->id)->update(['oom_killer' => !$server->oom_disabled]); + }); + + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('oom_disabled'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('servers', function (Blueprint $table) { + $table->tinyInteger('oom_disabled')->unsigned()->default(0)->after('oom_killer'); + }); + + DB::table('servers')->select(['id', 'oom_killer'])->cursor()->each(function ($server) { + DB::table('servers')->where('id', $server->id)->update(['oom_disabled' => !$server->oom_killer]); + }); + + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('oom_killer'); + }); + } +}; diff --git a/database/schema/mysql-schema.sql b/database/schema/mysql-schema.sql index 55d5b0ae2..f1d1f6c94 100644 --- a/database/schema/mysql-schema.sql +++ b/database/schema/mysql-schema.sql @@ -495,7 +495,7 @@ CREATE TABLE `servers` ( `io` int unsigned NOT NULL, `cpu` int unsigned NOT NULL, `threads` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `oom_disabled` tinyint unsigned NOT NULL DEFAULT '0', + `oom_killer` tinyint unsigned NOT NULL DEFAULT '0', `allocation_id` int unsigned NOT NULL, `egg_id` int unsigned NOT NULL, `startup` text COLLATE utf8mb4_unicode_ci NOT NULL, diff --git a/resources/views/admin/servers/new.blade.php b/resources/views/admin/servers/new.blade.php index f3f998046..4aac49d39 100644 --- a/resources/views/admin/servers/new.blade.php +++ b/resources/views/admin/servers/new.blade.php @@ -203,8 +203,8 @@
Terminates the server if it breaches the memory limits. Enabling OOM killer may cause server processes to exit unexpectedly.
diff --git a/resources/views/admin/servers/view/build.blade.php b/resources/views/admin/servers/view/build.blade.php index 655ea36af..8f7497728 100644 --- a/resources/views/admin/servers/view/build.blade.php +++ b/resources/views/admin/servers/view/build.blade.php @@ -74,11 +74,11 @@diff --git a/tests/Integration/Services/Servers/BuildModificationServiceTest.php b/tests/Integration/Services/Servers/BuildModificationServiceTest.php index 9e4b263fd..152b11039 100644 --- a/tests/Integration/Services/Servers/BuildModificationServiceTest.php +++ b/tests/Integration/Services/Servers/BuildModificationServiceTest.php @@ -114,7 +114,7 @@ class BuildModificationServiceTest extends IntegrationTestCase $this->daemonServerRepository->expects('sync')->withNoArgs()->andReturnUndefined(); $response = $this->getService()->handle($server, [ - 'oom_disabled' => false, + 'oom_killer' => false, 'memory' => 256, 'swap' => 128, 'io' => 600, @@ -126,7 +126,7 @@ class BuildModificationServiceTest extends IntegrationTestCase 'allocation_limit' => 20, ]); - $this->assertFalse($response->oom_disabled); + $this->assertFalse($response->oom_killer); $this->assertSame(256, $response->memory); $this->assertSame(128, $response->swap); $this->assertSame(600, $response->io); diff --git a/tests/Integration/Services/Servers/ServerCreationServiceTest.php b/tests/Integration/Services/Servers/ServerCreationServiceTest.php index 8d3df350a..c0b82a285 100644 --- a/tests/Integration/Services/Servers/ServerCreationServiceTest.php +++ b/tests/Integration/Services/Servers/ServerCreationServiceTest.php @@ -138,7 +138,7 @@ class ServerCreationServiceTest extends IntegrationTestCase $this->assertSame($allocations[4]->id, $response->allocations[1]->id); $this->assertFalse($response->isSuspended()); - $this->assertTrue($response->oom_disabled); + $this->assertFalse($response->oom_killer); $this->assertSame(0, $response->database_limit); $this->assertSame(0, $response->allocation_limit); $this->assertSame(0, $response->backup_limit);