diff --git a/app/Http/Controllers/Admin/OptionController.php b/app/Http/Controllers/Admin/OptionController.php index 9486f008a..f7c5ac6db 100644 --- a/app/Http/Controllers/Admin/OptionController.php +++ b/app/Http/Controllers/Admin/OptionController.php @@ -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())); diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 1a8a8cfbc..509656952 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -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. * diff --git a/app/Http/Controllers/Daemon/OptionController.php b/app/Http/Controllers/Daemon/OptionController.php index 087b1f503..9a27c1c64 100644 --- a/app/Http/Controllers/Daemon/OptionController.php +++ b/app/Http/Controllers/Daemon/OptionController.php @@ -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, diff --git a/app/Repositories/OptionRepository.php b/app/Repositories/OptionRepository.php index 4556063d5..53dab8c57 100644 --- a/app/Repositories/OptionRepository.php +++ b/app/Repositories/OptionRepository.php @@ -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()) { diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index e782c938a..adb14672e 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -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'); + }); + } } diff --git a/database/migrations/2017_04_20_171943_AddScriptsToServiceOptions.php b/database/migrations/2017_04_20_171943_AddScriptsToServiceOptions.php index aeee7507f..fb6d2da81 100644 --- a/database/migrations/2017_04_20_171943_AddScriptsToServiceOptions.php +++ b/database/migrations/2017_04_20_171943_AddScriptsToServiceOptions.php @@ -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'); }); } } diff --git a/resources/themes/pterodactyl/admin/servers/view/manage.blade.php b/resources/themes/pterodactyl/admin/servers/view/manage.blade.php index 00043f221..0566a8a1c 100644 --- a/resources/themes/pterodactyl/admin/servers/view/manage.blade.php +++ b/resources/themes/pterodactyl/admin/servers/view/manage.blade.php @@ -53,6 +53,22 @@
This will reinstall the server with the assigned pack and service scripts. Danger! This could overwrite server data.
+Docker container to use when running this script for the server.
+The entrypoint command to use for this script.
+