mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-07 00:42:34 +00:00
#591 - server-settings
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Models\Server;
|
||||
use App\ValidationRules\RestrictedIPAddressesRule;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
@ -17,6 +18,8 @@ class EditServer
|
||||
*/
|
||||
public function edit(Server $server, array $input): Server
|
||||
{
|
||||
Validator::make($input, self::rules($server))->validate();
|
||||
|
||||
$checkConnection = false;
|
||||
if (isset($input['name'])) {
|
||||
$server->name = $input['name'];
|
||||
@ -62,6 +65,7 @@ public static function rules(Server $server): array
|
||||
Rule::unique('servers')->where('project_id', $server->project_id)->ignore($server->id),
|
||||
],
|
||||
'local_ip' => [
|
||||
'nullable',
|
||||
'string',
|
||||
Rule::unique('servers')->where('project_id', $server->project_id)->ignore($server->id),
|
||||
],
|
||||
|
29
app/Console/Commands/CheckServersConnectionCommand.php
Normal file
29
app/Console/Commands/CheckServersConnectionCommand.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\ServerStatus;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CheckServersConnectionCommand extends Command
|
||||
{
|
||||
protected $signature = 'servers:check';
|
||||
|
||||
protected $description = 'Check servers connection status';
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
Server::query()->whereIn('status', [
|
||||
ServerStatus::READY,
|
||||
ServerStatus::DISCONNECTED,
|
||||
])->chunk(50, function ($servers) {
|
||||
/** @var Server $server */
|
||||
foreach ($servers as $server) {
|
||||
dispatch(function () use ($server) {
|
||||
$server->checkConnection();
|
||||
})->onConnection('ssh');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ protected function schedule(Schedule $schedule): void
|
||||
$schedule->command('backups:run "0 0 1 * *"')->monthly();
|
||||
$schedule->command('metrics:delete-older-metrics')->daily();
|
||||
$schedule->command('metrics:get')->everyMinute();
|
||||
$schedule->command('servers:check')->everyFiveMinutes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,9 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Server\CreateServer;
|
||||
use App\Actions\Server\RebootServer;
|
||||
use App\Actions\Server\Update;
|
||||
use App\Exceptions\SSHError;
|
||||
use App\Http\Resources\ServerLogResource;
|
||||
use App\Http\Resources\ServerProviderResource;
|
||||
use App\Http\Resources\ServerResource;
|
||||
@ -120,6 +123,39 @@ public function status(Server $server): RedirectResponse
|
||||
]));
|
||||
}
|
||||
|
||||
#[Post('/{server}/reboot', name: 'servers.reboot')]
|
||||
public function reboot(Server $server): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $server);
|
||||
|
||||
app(RebootServer::class)->reboot($server);
|
||||
|
||||
return back()->with('success', 'Server is being rebooted.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
#[Post('/{server}/check-for-updates', name: 'servers.check-for-updates')]
|
||||
public function checkForUpdates(Server $server): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $server);
|
||||
|
||||
$server->checkForUpdates();
|
||||
|
||||
return back()->with('info', 'Available updates: '.$server->refresh()->available_updates);
|
||||
}
|
||||
|
||||
#[Post('/{server}/update', name: 'servers.update')]
|
||||
public function update(Server $server): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $server);
|
||||
|
||||
app(Update::class)->update($server);
|
||||
|
||||
return back()->with('info', 'Server is being updated. This may take a while.');
|
||||
}
|
||||
|
||||
#[Delete('/{server}', name: 'servers.destroy')]
|
||||
public function destroy(Server $server, Request $request): RedirectResponse
|
||||
{
|
||||
|
37
app/Http/Controllers/ServerSettingController.php
Normal file
37
app/Http/Controllers/ServerSettingController.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Server\EditServer;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Spatie\RouteAttributes\Attributes\Get;
|
||||
use Spatie\RouteAttributes\Attributes\Middleware;
|
||||
use Spatie\RouteAttributes\Attributes\Patch;
|
||||
use Spatie\RouteAttributes\Attributes\Prefix;
|
||||
|
||||
#[Prefix('servers/{server}/settings')]
|
||||
#[Middleware(['auth', 'has-project'])]
|
||||
class ServerSettingController extends Controller
|
||||
{
|
||||
#[Get('/', name: 'server-settings')]
|
||||
public function index(Server $server): Response
|
||||
{
|
||||
$this->authorize('view', $server);
|
||||
|
||||
return Inertia::render('server-settings/index');
|
||||
}
|
||||
|
||||
#[Patch('update', name: 'server-settings.update')]
|
||||
public function update(Request $request, Server $server): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $server);
|
||||
|
||||
app(EditServer::class)->edit($server, $request->input());
|
||||
|
||||
return back()->with('success', 'Changes saved successfully.');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user