Add reinstall abilities and cleanup process for new servers
This commit is contained in:
parent
3fe5d162f5
commit
8dc24471ae
9 changed files with 91 additions and 3 deletions
|
@ -95,7 +95,7 @@ class OptionController extends Controller
|
|||
$repo = new VariableRepository;
|
||||
|
||||
try {
|
||||
$variable = $repo->create($id, $request->only([
|
||||
$variable = $repo->create($id, $request->intersect([
|
||||
'name', 'description', 'env_variable',
|
||||
'default_value', 'options', 'rules',
|
||||
]));
|
||||
|
@ -200,7 +200,7 @@ class OptionController extends Controller
|
|||
|
||||
try {
|
||||
if ($request->input('action') !== 'delete') {
|
||||
$variable = $repo->update($variable, $request->only([
|
||||
$variable = $repo->update($variable, $request->intersect([
|
||||
'name', 'description', 'env_variable',
|
||||
'default_value', 'options', 'rules',
|
||||
]));
|
||||
|
@ -233,7 +233,9 @@ class OptionController extends Controller
|
|||
$repo = new OptionRepository;
|
||||
|
||||
try {
|
||||
$repo->scripts($id, $request->only('script_install'));
|
||||
$repo->scripts($id, $request->only([
|
||||
'script_install', 'script_entry', 'script_container',
|
||||
]));
|
||||
Alert::success('Successfully updated option scripts to be run when servers are installed.')->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.option.scripts', $id)->withErrors(json_decode($ex->getMessage()));
|
||||
|
|
|
@ -322,6 +322,30 @@ class ServersController extends Controller
|
|||
return redirect()->route('admin.servers.view.manage', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reinstalls the server with the currently assigned pack and service.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function reinstallServer(Request $request, $id)
|
||||
{
|
||||
$repo = new ServerRepository;
|
||||
try {
|
||||
$repo->reinstall($id);
|
||||
|
||||
Alert::success('Server successfully marked for reinstallation.')->flash();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unhandled exception occured while attemping to perform this reinstallation. This error has been logged.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.servers.view.manage', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a server to have a container rebuild.
|
||||
*
|
||||
|
|
|
@ -44,6 +44,10 @@ class OptionController extends Controller
|
|||
'install' => (! $server->option->script_install) ? null : str_replace(["\r\n", "\n", "\r"], "\n", $server->option->script_install),
|
||||
'privileged' => $server->option->script_is_privileged,
|
||||
],
|
||||
'config' => [
|
||||
'container' => $server->option->script_container,
|
||||
'entry' => $server->option->script_entry,
|
||||
],
|
||||
'env' => $environment->merge([
|
||||
'STARTUP=' . $server->startup,
|
||||
'SERVER_MEMORY=' . $server->memory,
|
||||
|
|
|
@ -173,6 +173,8 @@ class OptionRepository
|
|||
$validator = Validator::make($data, [
|
||||
'script_install' => 'sometimes|nullable|string',
|
||||
'script_is_privileged' => 'sometimes|required|boolean',
|
||||
'script_entry' => 'sometimes|required|string',
|
||||
'script_container' => 'sometimes|required|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
|
|
@ -864,4 +864,25 @@ class ServerRepository
|
|||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a server for reinstallation on the node.
|
||||
*
|
||||
* @param int $id
|
||||
* @return void
|
||||
*/
|
||||
public function reinstall($id)
|
||||
{
|
||||
$server = Models\Server::with('node')->findOrFail($id);
|
||||
|
||||
DB::transaction(function () use ($server) {
|
||||
$server->installed = 0;
|
||||
$server->save();
|
||||
|
||||
$server->node->guzzleClient([
|
||||
'X-Access-Token' => $server->node->daemonSecret,
|
||||
'X-Access-Server' => $server->uuid,
|
||||
])->request('POST', '/server/reinstall');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ class AddScriptsToServiceOptions extends Migration
|
|||
Schema::table('service_options', function (Blueprint $table) {
|
||||
$table->text('script_install')->after('startup')->nullable();
|
||||
$table->boolean('script_is_privileged')->default(true)->after('startup');
|
||||
$table->text('script_entry')->default('ash')->after('startup');
|
||||
$table->text('script_container')->default('alpine:3.4')->after('startup');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -29,6 +31,8 @@ class AddScriptsToServiceOptions extends Migration
|
|||
Schema::table('service_options', function (Blueprint $table) {
|
||||
$table->dropColumn('script_install');
|
||||
$table->dropColumn('script_is_privileged');
|
||||
$table->dropColumn('script_entry');
|
||||
$table->dropColumn('script_container');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,22 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Reinstall Server</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<p>This will reinstall the server with the assigned pack and service scripts. <strong>Danger!</strong> This could overwrite server data.</p>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<form action="{{ route('admin.servers.view.manage.reinstall', $server->id) }}" method="POST">
|
||||
{!! csrf_field() !!}
|
||||
<button type="submit" class="btn btn-danger">Reinstall Server</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
|
|
|
@ -55,6 +55,20 @@
|
|||
<div class="box-body no-padding">
|
||||
<div id="editor_install"style="height:300px">{{ $option->script_install }}</div>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-6">
|
||||
<label class="control-label">Script Container</label>
|
||||
<input type="text" name="script_container" class="form-control" value="{{ $option->script_container }}" />
|
||||
<p class="text-muted small">Docker container to use when running this script for the server.</p>
|
||||
</div>
|
||||
<div class="form-group col-sm-6">
|
||||
<label class="control-label">Script Entrypoint Command</label>
|
||||
<input type="text" name="script_entry" class="form-control" value="{{ $option->script_entry }}" />
|
||||
<p class="text-muted small">The entrypoint command to use for this script.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
{!! csrf_field() !!}
|
||||
<textarea name="script_install" class="hidden"></textarea>
|
||||
|
|
|
@ -118,6 +118,7 @@ Route::group(['prefix' => 'servers'], function () {
|
|||
Route::post('/view/{id}/manage/toggle', 'ServersController@toggleInstall')->name('admin.servers.view.manage.toggle');
|
||||
Route::post('/view/{id}/manage/rebuild', 'ServersController@rebuildContainer')->name('admin.servers.view.manage.rebuild');
|
||||
Route::post('/view/{id}/manage/suspension', 'ServersController@manageSuspension')->name('admin.servers.view.manage.suspension');
|
||||
Route::post('/view/{id}/manage/reinstall', 'ServersController@reinstallServer')->name('admin.servers.view.manage.reinstall');
|
||||
Route::post('/view/{id}/delete', 'ServersController@delete');
|
||||
|
||||
Route::patch('/view/{id}/database', 'ServersController@resetDatabasePassword');
|
||||
|
|
Loading…
Reference in a new issue