From 6b25a163fcf63a34772d403ebf7f6dbc919d4da9 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 1 Jan 2016 22:53:43 -0500 Subject: [PATCH] Improved server creation and options --- .../Controllers/Admin/ServersController.php | 7 +- app/Repositories/ServerRepository.php | 10 ++- ...16_01_02_023924_add_new_server_options.php | 35 ++++++++++ ...16_01_02_024253_modify_service_options.php | 33 ++++++++++ ..._02_024552_modify_services_add_startup.php | 33 ++++++++++ resources/views/admin/servers/new.blade.php | 64 +++++++++++++++---- 6 files changed, 168 insertions(+), 14 deletions(-) create mode 100644 database/migrations/2016_01_02_023924_add_new_server_options.php create mode 100644 database/migrations/2016_01_02_024253_modify_service_options.php create mode 100644 database/migrations/2016_01_02_024552_modify_services_add_startup.php diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 299721ab..57227b6d 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -142,7 +142,12 @@ class ServersController extends Controller ], 500); } - return response()->json(Models\ServiceOptions::select('id', 'name', 'docker_image')->where('parent_service', $request->input('service'))->orderBy('name', 'asc')->get()); + $service = Models\Service::select('executable', 'startup')->where('id', $request->input('service'))->first(); + return response()->json([ + 'exec' => $service->executable, + 'startup' => $service->startup, + 'options' => Models\ServiceOptions::select('id', 'name', 'docker_image')->where('parent_service', $request->input('service'))->orderBy('name', 'asc')->get() + ]); } diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 131a8ac5..d383917a 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -52,6 +52,7 @@ class ServerRepository 'node' => 'required|numeric|min:1|exists:nodes,id', 'name' => 'required|regex:([\w -]{4,35})', 'memory' => 'required|numeric|min:1', + 'swap' => 'required|numeric|min:0', 'disk' => 'required|numeric|min:1', 'cpu' => 'required|numeric|min:0', 'io' => 'required|numeric|min:10|max:1000', @@ -59,6 +60,7 @@ class ServerRepository 'port' => 'required|numeric|min:1|max:65535', 'service' => 'required|numeric|min:1|exists:services,id', 'option' => 'required|numeric|min:1|exists:service_options,id', + 'startup' => 'required', 'custom_image_name' => 'required_if:use_custom_image,on', ]); @@ -155,21 +157,25 @@ class ServerRepository // Add Server to the Database $server = new Models\Server; + $generatedUuid = $uuid->generate('servers', 'uuid'); $server->fill([ - 'uuid' => $uuid->generate('servers', 'uuid'), - 'uuidShort' => $uuid->generateShort(), + 'uuid' => $generatedUuid, + 'uuidShort' => $uuid->generateShort('servers', 'uuidShort', $generatedUuid), 'node' => $data['node'], 'name' => $data['name'], 'active' => 1, 'owner' => $user->id, 'memory' => $data['memory'], + 'swap' => $data['swap'], 'disk' => $data['disk'], 'io' => $data['io'], 'cpu' => $data['cpu'], + 'oom_disabled' => (isset($data['oom_disabled'])) ? true : false, 'ip' => $data['ip'], 'port' => $data['port'], 'service' => $data['service'], 'option' => $data['option'], + 'startup' => $data['startup'], 'daemonSecret' => $uuid->generate('servers', 'daemonSecret'), 'username' => $this->generateSFTPUsername($data['name']) ]); diff --git a/database/migrations/2016_01_02_023924_add_new_server_options.php b/database/migrations/2016_01_02_023924_add_new_server_options.php new file mode 100644 index 00000000..7a9b7f7e --- /dev/null +++ b/database/migrations/2016_01_02_023924_add_new_server_options.php @@ -0,0 +1,35 @@ +boolean('oom_disabled')->default(false)->after('cpu'); + $table->mediumInteger('swap')->default(0)->after('memory'); + $table->text('startup')->after('option'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('oom_enabled'); + $table->dropColumn('swap'); + $table->dropColumn('startup'); + }); + } +} diff --git a/database/migrations/2016_01_02_024253_modify_service_options.php b/database/migrations/2016_01_02_024253_modify_service_options.php new file mode 100644 index 00000000..840da3bd --- /dev/null +++ b/database/migrations/2016_01_02_024253_modify_service_options.php @@ -0,0 +1,33 @@ +dropColumn('config_file'); + $table->dropColumn('config_blob'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('service_options', function (Blueprint $table) { + $table->string('config_file')->after('description'); + $table->binary('config_blob')->after('config_file'); + }); + } +} diff --git a/database/migrations/2016_01_02_024552_modify_services_add_startup.php b/database/migrations/2016_01_02_024552_modify_services_add_startup.php new file mode 100644 index 00000000..38214a7b --- /dev/null +++ b/database/migrations/2016_01_02_024552_modify_services_add_startup.php @@ -0,0 +1,33 @@ +text('executable')->after('description'); + $table->text('startup')->after('executable'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('services', function (Blueprint $table) { + $table->dropColumn('executable'); + $table->dropColumn('startup'); + }); + } +} diff --git a/resources/views/admin/servers/new.blade.php b/resources/views/admin/servers/new.blade.php index 272f506e..0865f17a 100644 --- a/resources/views/admin/servers/new.blade.php +++ b/resources/views/admin/servers/new.blade.php @@ -96,31 +96,56 @@
-
+
MB
-
+
+ +
+ + MB +
+
+
+ +
+ + + + + Disable OOM Killer + +
+
+
+
+
+

If you do not want to assign swap space to a server simply put 0 for the value. We suggest leaving OOM Killer enabled unless you know what you are doing, disabling it could cause your server to hang unexpectedly.

+

+
+
+
MB
-
+
- + %
-
+
- + I/O
@@ -167,7 +192,7 @@
- +
@@ -177,11 +202,20 @@
-
+ \ '; $('#serverVariables').append(dataAppend); }); + $('#serviceOptions').slideDown(); }).fail(function (jqXHR) { console.error(jqXHR); }).always(function () { handleLoader('#load_services'); + handleLoader('#serviceOptions'); }); });