Skip to content

Commit 6b25a16

Browse files
committed
Improved server creation and options
1 parent 8b8ef4f commit 6b25a16

File tree

6 files changed

+168
-14
lines changed

6 files changed

+168
-14
lines changed

app/Http/Controllers/Admin/ServersController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ public function postNewServerServiceOptions(Request $request)
142142
], 500);
143143
}
144144

145-
return response()->json(Models\ServiceOptions::select('id', 'name', 'docker_image')->where('parent_service', $request->input('service'))->orderBy('name', 'asc')->get());
145+
$service = Models\Service::select('executable', 'startup')->where('id', $request->input('service'))->first();
146+
return response()->json([
147+
'exec' => $service->executable,
148+
'startup' => $service->startup,
149+
'options' => Models\ServiceOptions::select('id', 'name', 'docker_image')->where('parent_service', $request->input('service'))->orderBy('name', 'asc')->get()
150+
]);
146151

147152
}
148153

app/Repositories/ServerRepository.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ public function create(array $data)
5252
'node' => 'required|numeric|min:1|exists:nodes,id',
5353
'name' => 'required|regex:([\w -]{4,35})',
5454
'memory' => 'required|numeric|min:1',
55+
'swap' => 'required|numeric|min:0',
5556
'disk' => 'required|numeric|min:1',
5657
'cpu' => 'required|numeric|min:0',
5758
'io' => 'required|numeric|min:10|max:1000',
5859
'ip' => 'required|ip',
5960
'port' => 'required|numeric|min:1|max:65535',
6061
'service' => 'required|numeric|min:1|exists:services,id',
6162
'option' => 'required|numeric|min:1|exists:service_options,id',
63+
'startup' => 'required',
6264
'custom_image_name' => 'required_if:use_custom_image,on',
6365
]);
6466

@@ -155,21 +157,25 @@ public function create(array $data)
155157

156158
// Add Server to the Database
157159
$server = new Models\Server;
160+
$generatedUuid = $uuid->generate('servers', 'uuid');
158161
$server->fill([
159-
'uuid' => $uuid->generate('servers', 'uuid'),
160-
'uuidShort' => $uuid->generateShort(),
162+
'uuid' => $generatedUuid,
163+
'uuidShort' => $uuid->generateShort('servers', 'uuidShort', $generatedUuid),
161164
'node' => $data['node'],
162165
'name' => $data['name'],
163166
'active' => 1,
164167
'owner' => $user->id,
165168
'memory' => $data['memory'],
169+
'swap' => $data['swap'],
166170
'disk' => $data['disk'],
167171
'io' => $data['io'],
168172
'cpu' => $data['cpu'],
173+
'oom_disabled' => (isset($data['oom_disabled'])) ? true : false,
169174
'ip' => $data['ip'],
170175
'port' => $data['port'],
171176
'service' => $data['service'],
172177
'option' => $data['option'],
178+
'startup' => $data['startup'],
173179
'daemonSecret' => $uuid->generate('servers', 'daemonSecret'),
174180
'username' => $this->generateSFTPUsername($data['name'])
175181
]);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class AddNewServerOptions extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('servers', function (Blueprint $table) {
16+
$table->boolean('oom_disabled')->default(false)->after('cpu');
17+
$table->mediumInteger('swap')->default(0)->after('memory');
18+
$table->text('startup')->after('option');
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
Schema::table('servers', function (Blueprint $table) {
30+
$table->dropColumn('oom_enabled');
31+
$table->dropColumn('swap');
32+
$table->dropColumn('startup');
33+
});
34+
}
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class ModifyServiceOptions extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('service_options', function (Blueprint $table) {
16+
$table->dropColumn('config_file');
17+
$table->dropColumn('config_blob');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('service_options', function (Blueprint $table) {
29+
$table->string('config_file')->after('description');
30+
$table->binary('config_blob')->after('config_file');
31+
});
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class ModifyServicesAddStartup extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('services', function (Blueprint $table) {
16+
$table->text('executable')->after('description');
17+
$table->text('startup')->after('executable');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('services', function (Blueprint $table) {
29+
$table->dropColumn('executable');
30+
$table->dropColumn('startup');
31+
});
32+
}
33+
}

resources/views/admin/servers/new.blade.php

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,31 +96,56 @@
9696
</div>
9797
<div class="well">
9898
<div class="row">
99-
<div class="form-group col-md-3 col-xs-6">
99+
<div class="form-group col-md-4 col-xs-4">
100100
<label for="memory" class="control-label">Memory</label>
101101
<div class="input-group">
102102
<input type="text" name="memory" class="form-control" value="{{ old('memory') }}"/>
103103
<span class="input-group-addon">MB</span>
104104
</div>
105105
</div>
106-
<div class="form-group col-md-3 col-xs-6">
106+
<div class="form-group col-md-4 col-xs-4">
107+
<label for="memory" class="control-label">Swap</label>
108+
<div class="input-group">
109+
<input type="text" name="swap" class="form-control" value="{{ old('swap', 0) }}"/>
110+
<span class="input-group-addon">MB</span>
111+
</div>
112+
</div>
113+
<div class="form-group col-md-4 col-xs-4">
114+
<label for="memory" class="control-label">OOM Killer</label>
115+
<div>
116+
<span class="input-group-addon" style="height:36px;">
117+
<input type="checkbox" name="oom_disabled"/>
118+
</span>
119+
<span class="input-group-addon" style="height:36px;">
120+
Disable OOM Killer
121+
</span>
122+
</div>
123+
</div>
124+
</div>
125+
<div class="row">
126+
<div class="col-md-12">
127+
<p class="text-muted"><small>If you do not want to assign swap space to a server simply put <code>0</code> 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.</small><p>
128+
</div>
129+
</div>
130+
<div class="row">
131+
<div class="form-group col-md-4 col-xs-4">
107132
<label for="disk" class="control-label">Disk Space</label>
108133
<div class="input-group">
109134
<input type="text" name="disk" class="form-control" value="{{ old('disk') }}"/>
110135
<span class="input-group-addon">MB</span>
111136
</div>
112137
</div>
113-
<div class="form-group col-md-3 col-xs-6">
138+
<div class="form-group col-md-4 col-xs-4">
114139
<label for="cpu" class="control-label">CPU Limit</label>
115140
<div class="input-group">
116-
<input type="text" name="cpu" value="0" class="form-control" value="{{ old('cpu') }}"/>
141+
<input type="text" name="cpu" class="form-control" value="{{ old('cpu', 0) }}"/>
117142
<span class="input-group-addon">%</span>
118143
</div>
119144
</div>
120-
<div class="form-group col-md-3 col-xs-6">
145+
<div class="form-group col-md-4 col-xs-4">
121146
<label for="io" class="control-label">Block I/O</label>
122147
<div class="input-group">
123-
<input type="text" name="io" value="500" class="form-control" value="{{ old('io') }}"/>
148+
<input type="text" name="io" class="form-control" value="{{ old('io', 500) }}"/>
124149
<span class="input-group-addon">I/O</span>
125150
</div>
126151
</div>
@@ -167,7 +192,7 @@
167192
<label for="use_custom_image" class="control-label">Use Custom Docker Image</label>
168193
<div class="input-group">
169194
<span class="input-group-addon">
170-
<input @if(old('name') === 'use_custom_image')checked="checked"@endif type="checkbox" name="use_custom_image"/>
195+
<input @if(old('use_custom_image') === 'use_custom_image')checked="checked"@endif type="checkbox" name="use_custom_image"/>
171196
</span>
172197
<input type="text" class="form-control" name="custom_image_name" value="{{ old('custom_image_name') }}" disabled />
173198
</div>
@@ -177,11 +202,20 @@
177202
</div>
178203
</div>
179204
</div>
180-
<div class="well">
205+
<div class="well" id="serviceOptions" style="display:none;">
181206
<div class="row">
182-
<div class="col-md-12">
183-
<h3 class="nopad">Service Environment Variables</h3>
207+
<div class="form-group col-md-12">
208+
<h3 class="nopad">Service Setup &amp; Options</h3>
184209
<hr />
210+
<label for="startup" class="control-label">Startup Command</label>
211+
<div class="input-group">
212+
<span class="input-group-addon" id="startupExec"></span>
213+
<input type="text" class="form-control" name="startup" value="{{ old('startup') }}" />
214+
</div>
215+
</div>
216+
</div>
217+
<div class="row">
218+
<div class="col-md-12">
185219
<div class="alert alert-info">Some service options have additional environment variables that you can define for a given instance. They will show up below when you select a service option. If none show up, chances are that none were defined, and there is nothing to worry about.</div>
186220
<span id="serverVariables"></span>
187221
</div>
@@ -313,6 +347,8 @@
313347
314348
currentService = $('#getService').val();
315349
handleLoader('#load_services', true);
350+
$('#serviceOptions').slideUp();
351+
$('#getOption').html('<option disabled selected> -- Select a Service Option</option>');
316352
317353
$.ajax({
318354
method: 'POST',
@@ -324,7 +360,9 @@
324360
service: $('#getService').val()
325361
}
326362
}).done(function (data) {
327-
$.each(data, function (i, option) {
363+
$('#startupExec').html(data.exec);
364+
$('input[name="startup"]').val(data.startup);
365+
$.each(data.options, function (i, option) {
328366
$('#getOption').append('<option value="' + option.id + '" data-image="' + option.docker_image + '">' + option.name + '</option>');
329367
});
330368
$('#getOption').parent().parent().removeClass('hidden');
@@ -341,6 +379,7 @@
341379
$('#getOption').on('change', function (event) {
342380
343381
handleLoader('#load_services', true);
382+
handleLoader('#serviceOptions', true);
344383
$('#serverVariables').html('');
345384
$('input[name="custom_image_name"]').val($(this).find(':selected').data('image'));
346385
@@ -363,15 +402,18 @@
363402
<input type="text" autocomplete="off" name="env_' + item.env_variable + '" class="form-control" value="' + item.default_value + '" />\
364403
<p class="text-muted"><small>' + item.description + '</small></p>\
365404
<p class="text-muted"><small>Regex Requirements for Input: <code>' + item.regex + '</code></small></p>\
405+
<p class="text-muted"><small>Access in Startup: <code>${' + item.env_variable + '}</code></small></p>\
366406
</div>\
367407
</div>\
368408
';
369409
$('#serverVariables').append(dataAppend);
370410
});
411+
$('#serviceOptions').slideDown();
371412
}).fail(function (jqXHR) {
372413
console.error(jqXHR);
373414
}).always(function () {
374415
handleLoader('#load_services');
416+
handleLoader('#serviceOptions');
375417
});
376418
377419
});

0 commit comments

Comments
 (0)