mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-20 02:11:36 +00:00
add enable/disable services
This commit is contained in:
parent
7a6dcb5654
commit
77d6914cd9
@ -51,4 +51,34 @@ public function restart(Service $service): void
|
|||||||
$service->save();
|
$service->save();
|
||||||
})->onConnection('ssh');
|
})->onConnection('ssh');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function enable(Service $service): void
|
||||||
|
{
|
||||||
|
$service->status = ServiceStatus::ENABLING;
|
||||||
|
$service->save();
|
||||||
|
dispatch(function () use ($service) {
|
||||||
|
$status = $service->server->systemd()->enable($service->unit);
|
||||||
|
if (str($status)->contains('Active: active')) {
|
||||||
|
$service->status = ServiceStatus::READY;
|
||||||
|
} else {
|
||||||
|
$service->status = ServiceStatus::FAILED;
|
||||||
|
}
|
||||||
|
$service->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disable(Service $service): void
|
||||||
|
{
|
||||||
|
$service->status = ServiceStatus::DISABLING;
|
||||||
|
$service->save();
|
||||||
|
dispatch(function () use ($service) {
|
||||||
|
$status = $service->server->systemd()->disable($service->unit);
|
||||||
|
if (str($status)->contains('Active: inactive')) {
|
||||||
|
$service->status = ServiceStatus::DISABLED;
|
||||||
|
} else {
|
||||||
|
$service->status = ServiceStatus::FAILED;
|
||||||
|
}
|
||||||
|
$service->save();
|
||||||
|
})->onConnection('ssh');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,4 +23,10 @@ final class ServiceStatus extends Enum
|
|||||||
const RESTARTING = 'restarting';
|
const RESTARTING = 'restarting';
|
||||||
|
|
||||||
const STOPPED = 'stopped';
|
const STOPPED = 'stopped';
|
||||||
|
|
||||||
|
const ENABLING = 'enabling';
|
||||||
|
|
||||||
|
const DISABLING = 'disabling';
|
||||||
|
|
||||||
|
const DISABLED = 'disabled';
|
||||||
}
|
}
|
||||||
|
@ -44,4 +44,22 @@ public function restart(Server $server, Service $service): RedirectResponse
|
|||||||
|
|
||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function enable(Server $server, Service $service): RedirectResponse
|
||||||
|
{
|
||||||
|
$service->enable();
|
||||||
|
|
||||||
|
Toast::success('Service is being enabled!');
|
||||||
|
|
||||||
|
return back();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disable(Server $server, Service $service): RedirectResponse
|
||||||
|
{
|
||||||
|
$service->disable();
|
||||||
|
|
||||||
|
Toast::success('Service is being disabled!');
|
||||||
|
|
||||||
|
return back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,4 +93,14 @@ public function restart(): void
|
|||||||
{
|
{
|
||||||
app(Manage::class)->restart($this);
|
app(Manage::class)->restart($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function enable(): void
|
||||||
|
{
|
||||||
|
app(Manage::class)->enable($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disable(): void
|
||||||
|
{
|
||||||
|
app(Manage::class)->disable($this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public function __construct(protected Server $server)
|
|||||||
public function status(string $unit): string
|
public function status(string $unit): string
|
||||||
{
|
{
|
||||||
$command = <<<EOD
|
$command = <<<EOD
|
||||||
sudo service $unit status | cat
|
sudo systemctl status $unit | cat
|
||||||
EOD;
|
EOD;
|
||||||
|
|
||||||
return $this->server->ssh()->exec($command, sprintf('status-%s', $unit));
|
return $this->server->ssh()->exec($command, sprintf('status-%s', $unit));
|
||||||
@ -22,8 +22,8 @@ public function status(string $unit): string
|
|||||||
public function start(string $unit): string
|
public function start(string $unit): string
|
||||||
{
|
{
|
||||||
$command = <<<EOD
|
$command = <<<EOD
|
||||||
sudo service $unit start
|
sudo systemctl start $unit
|
||||||
sudo service $unit status | cat
|
sudo systemctl status $unit | cat
|
||||||
EOD;
|
EOD;
|
||||||
|
|
||||||
return $this->server->ssh()->exec($command, sprintf('start-%s', $unit));
|
return $this->server->ssh()->exec($command, sprintf('start-%s', $unit));
|
||||||
@ -32,8 +32,8 @@ public function start(string $unit): string
|
|||||||
public function stop(string $unit): string
|
public function stop(string $unit): string
|
||||||
{
|
{
|
||||||
$command = <<<EOD
|
$command = <<<EOD
|
||||||
sudo service $unit stop
|
sudo systemctl stop $unit
|
||||||
sudo service $unit status | cat
|
sudo systemctl status $unit | cat
|
||||||
EOD;
|
EOD;
|
||||||
|
|
||||||
return $this->server->ssh()->exec($command, sprintf('stop-%s', $unit));
|
return $this->server->ssh()->exec($command, sprintf('stop-%s', $unit));
|
||||||
@ -42,10 +42,32 @@ public function stop(string $unit): string
|
|||||||
public function restart(string $unit): string
|
public function restart(string $unit): string
|
||||||
{
|
{
|
||||||
$command = <<<EOD
|
$command = <<<EOD
|
||||||
sudo service $unit restart
|
sudo systemctl restart $unit
|
||||||
sudo service $unit status | cat
|
sudo systemctl status $unit | cat
|
||||||
EOD;
|
EOD;
|
||||||
|
|
||||||
return $this->server->ssh()->exec($command, sprintf('restart-%s', $unit));
|
return $this->server->ssh()->exec($command, sprintf('restart-%s', $unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function enable(string $unit): string
|
||||||
|
{
|
||||||
|
$command = <<<EOD
|
||||||
|
sudo systemctl start $unit
|
||||||
|
sudo systemctl enable $unit
|
||||||
|
sudo systemctl status $unit | cat
|
||||||
|
EOD;
|
||||||
|
|
||||||
|
return $this->server->ssh()->exec($command, sprintf('enable-%s', $unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disable(string $unit): string
|
||||||
|
{
|
||||||
|
$command = <<<EOD
|
||||||
|
sudo systemctl stop $unit
|
||||||
|
sudo systemctl disable $unit
|
||||||
|
sudo systemctl status $unit | cat
|
||||||
|
EOD;
|
||||||
|
|
||||||
|
return $this->server->ssh()->exec($command, sprintf('disable-%s', $unit));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public function up(): void
|
|||||||
$table->json('type_data')->nullable();
|
$table->json('type_data')->nullable();
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->string('version');
|
$table->string('version');
|
||||||
$table->enum('status', ServiceStatus::getValues())->default(ServiceStatus::INSTALLING);
|
$table->string('status')->default(ServiceStatus::INSTALLING);
|
||||||
$table->boolean('is_default')->default(1);
|
$table->boolean('is_default')->default(1);
|
||||||
$table->string('unit')->nullable();
|
$table->string('unit')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Enums\DeploymentStatus;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@ -16,7 +15,7 @@ public function up(): void
|
|||||||
$table->unsignedInteger('log_id')->nullable();
|
$table->unsignedInteger('log_id')->nullable();
|
||||||
$table->json('commit_data')->nullable();
|
$table->json('commit_data')->nullable();
|
||||||
$table->string('commit_id')->nullable();
|
$table->string('commit_id')->nullable();
|
||||||
$table->enum('status', DeploymentStatus::getValues());
|
$table->string('status');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public function up(): void
|
|||||||
$table->id();
|
$table->id();
|
||||||
$table->unsignedBigInteger('server_id');
|
$table->unsignedBigInteger('server_id');
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->enum('status', DatabaseStatus::getValues())->default(DatabaseStatus::CREATING);
|
$table->string('status')->default(DatabaseStatus::CREATING);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public function up(): void
|
|||||||
$table->longText('password')->nullable();
|
$table->longText('password')->nullable();
|
||||||
$table->json('databases')->nullable();
|
$table->json('databases')->nullable();
|
||||||
$table->string('host')->default('localhost');
|
$table->string('host')->default('localhost');
|
||||||
$table->enum('status', DatabaseUserStatus::getValues())->default(DatabaseUserStatus::CREATING);
|
$table->string('status')->default(DatabaseUserStatus::CREATING);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Enums\CronjobStatus;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@ -16,7 +15,7 @@ public function up(): void
|
|||||||
$table->string('user');
|
$table->string('user');
|
||||||
$table->string('frequency');
|
$table->string('frequency');
|
||||||
$table->boolean('hidden')->default(0);
|
$table->boolean('hidden')->default(0);
|
||||||
$table->enum('status', CronjobStatus::getValues());
|
$table->string('status');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Enums\SslStatus;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@ -18,7 +17,7 @@ public function up(): void
|
|||||||
$table->longText('pk')->nullable();
|
$table->longText('pk')->nullable();
|
||||||
$table->longText('ca')->nullable();
|
$table->longText('ca')->nullable();
|
||||||
$table->timestamp('expires_at');
|
$table->timestamp('expires_at');
|
||||||
$table->enum('status', SslStatus::getValues());
|
$table->string('status');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Enums\QueueStatus;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@ -20,7 +19,7 @@ public function up(): void
|
|||||||
$table->tinyInteger('numprocs')->default(8);
|
$table->tinyInteger('numprocs')->default(8);
|
||||||
$table->boolean('redirect_stderr')->default(1);
|
$table->boolean('redirect_stderr')->default(1);
|
||||||
$table->string('stdout_logfile')->nullable();
|
$table->string('stdout_logfile')->nullable();
|
||||||
$table->enum('status', QueueStatus::getValues());
|
$table->string('status');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Enums\SshKeyStatus;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@ -13,7 +12,7 @@ public function up(): void
|
|||||||
$table->id();
|
$table->id();
|
||||||
$table->unsignedBigInteger('server_id');
|
$table->unsignedBigInteger('server_id');
|
||||||
$table->unsignedBigInteger('ssh_key_id');
|
$table->unsignedBigInteger('ssh_key_id');
|
||||||
$table->enum('status', SshKeyStatus::getValues());
|
$table->string('status');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,22 @@ class="cursor-pointer"
|
|||||||
>
|
>
|
||||||
{{ __("Restart") }}
|
{{ __("Restart") }}
|
||||||
</x-dropdown-link>
|
</x-dropdown-link>
|
||||||
|
|
||||||
|
@if ($service->status == \App\Enums\ServiceStatus::DISABLED)
|
||||||
|
<x-dropdown-link
|
||||||
|
class="cursor-pointer"
|
||||||
|
href="{{ route('servers.services.enable', ['server' => $server, 'service' => $service]) }}"
|
||||||
|
>
|
||||||
|
{{ __("Enable") }}
|
||||||
|
</x-dropdown-link>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<x-dropdown-link
|
||||||
|
class="cursor-pointer"
|
||||||
|
href="{{ route('servers.services.disable', ['server' => $server, 'service' => $service]) }}"
|
||||||
|
>
|
||||||
|
{{ __("Disable") }}
|
||||||
|
</x-dropdown-link>
|
||||||
@endif
|
@endif
|
||||||
</x-slot>
|
</x-slot>
|
||||||
</x-dropdown>
|
</x-dropdown>
|
||||||
|
@ -33,3 +33,15 @@
|
|||||||
@if ($status == \App\Enums\ServiceStatus::STOPPED)
|
@if ($status == \App\Enums\ServiceStatus::STOPPED)
|
||||||
<x-status status="danger">{{ $status }}</x-status>
|
<x-status status="danger">{{ $status }}</x-status>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if ($status == \App\Enums\ServiceStatus::ENABLING)
|
||||||
|
<x-status status="warning">{{ $status }}</x-status>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if ($status == \App\Enums\ServiceStatus::DISABLING)
|
||||||
|
<x-status status="warning">{{ $status }}</x-status>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if ($status == \App\Enums\ServiceStatus::DISABLED)
|
||||||
|
<x-status status="disabled">{{ $status }}</x-status>
|
||||||
|
@endif
|
||||||
|
@ -119,6 +119,8 @@
|
|||||||
Route::get('/{server}/services/{service}/start', [ServiceController::class, 'start'])->name('servers.services.start');
|
Route::get('/{server}/services/{service}/start', [ServiceController::class, 'start'])->name('servers.services.start');
|
||||||
Route::get('/{server}/services/{service}/stop', [ServiceController::class, 'stop'])->name('servers.services.stop');
|
Route::get('/{server}/services/{service}/stop', [ServiceController::class, 'stop'])->name('servers.services.stop');
|
||||||
Route::get('/{server}/services/{service}/restart', [ServiceController::class, 'restart'])->name('servers.services.restart');
|
Route::get('/{server}/services/{service}/restart', [ServiceController::class, 'restart'])->name('servers.services.restart');
|
||||||
|
Route::get('/{server}/services/{service}/enable', [ServiceController::class, 'enable'])->name('servers.services.enable');
|
||||||
|
Route::get('/{server}/services/{service}/disable', [ServiceController::class, 'disable'])->name('servers.services.disable');
|
||||||
});
|
});
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
|
@ -44,6 +44,27 @@ public function test_restart_service(string $name): void
|
|||||||
$this->assertEquals(ServiceStatus::READY, $service->status);
|
$this->assertEquals(ServiceStatus::READY, $service->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider data
|
||||||
|
*/
|
||||||
|
public function test_failed_to_restart_service(string $name): void
|
||||||
|
{
|
||||||
|
$this->actingAs($this->user);
|
||||||
|
|
||||||
|
$service = $this->server->services()->where('name', $name)->firstOrFail();
|
||||||
|
|
||||||
|
SSH::fake('Active: inactive');
|
||||||
|
|
||||||
|
$this->get(route('servers.services.restart', [
|
||||||
|
'server' => $this->server,
|
||||||
|
'service' => $service,
|
||||||
|
]))->assertSessionDoesntHaveErrors();
|
||||||
|
|
||||||
|
$service->refresh();
|
||||||
|
|
||||||
|
$this->assertEquals(ServiceStatus::FAILED, $service->status);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider data
|
* @dataProvider data
|
||||||
*/
|
*/
|
||||||
@ -65,6 +86,27 @@ public function test_stop_service(string $name): void
|
|||||||
$this->assertEquals(ServiceStatus::STOPPED, $service->status);
|
$this->assertEquals(ServiceStatus::STOPPED, $service->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider data
|
||||||
|
*/
|
||||||
|
public function test_failed_to_stop_service(string $name): void
|
||||||
|
{
|
||||||
|
$this->actingAs($this->user);
|
||||||
|
|
||||||
|
$service = $this->server->services()->where('name', $name)->firstOrFail();
|
||||||
|
|
||||||
|
SSH::fake('Active: active');
|
||||||
|
|
||||||
|
$this->get(route('servers.services.stop', [
|
||||||
|
'server' => $this->server,
|
||||||
|
'service' => $service,
|
||||||
|
]))->assertSessionDoesntHaveErrors();
|
||||||
|
|
||||||
|
$service->refresh();
|
||||||
|
|
||||||
|
$this->assertEquals(ServiceStatus::FAILED, $service->status);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider data
|
* @dataProvider data
|
||||||
*/
|
*/
|
||||||
@ -110,7 +152,28 @@ public function test_failed_to_start_service(string $name): void
|
|||||||
/**
|
/**
|
||||||
* @dataProvider data
|
* @dataProvider data
|
||||||
*/
|
*/
|
||||||
public function test_failed_to_restart_service(string $name): void
|
public function test_enable_service(string $name): void
|
||||||
|
{
|
||||||
|
$this->actingAs($this->user);
|
||||||
|
|
||||||
|
$service = $this->server->services()->where('name', $name)->firstOrFail();
|
||||||
|
|
||||||
|
SSH::fake('Active: active');
|
||||||
|
|
||||||
|
$this->get(route('servers.services.enable', [
|
||||||
|
'server' => $this->server,
|
||||||
|
'service' => $service,
|
||||||
|
]))->assertSessionDoesntHaveErrors();
|
||||||
|
|
||||||
|
$service->refresh();
|
||||||
|
|
||||||
|
$this->assertEquals(ServiceStatus::READY, $service->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider data
|
||||||
|
*/
|
||||||
|
public function test_failed_to_enable_service(string $name): void
|
||||||
{
|
{
|
||||||
$this->actingAs($this->user);
|
$this->actingAs($this->user);
|
||||||
|
|
||||||
@ -118,7 +181,7 @@ public function test_failed_to_restart_service(string $name): void
|
|||||||
|
|
||||||
SSH::fake('Active: inactive');
|
SSH::fake('Active: inactive');
|
||||||
|
|
||||||
$this->get(route('servers.services.restart', [
|
$this->get(route('servers.services.enable', [
|
||||||
'server' => $this->server,
|
'server' => $this->server,
|
||||||
'service' => $service,
|
'service' => $service,
|
||||||
]))->assertSessionDoesntHaveErrors();
|
]))->assertSessionDoesntHaveErrors();
|
||||||
@ -131,7 +194,28 @@ public function test_failed_to_restart_service(string $name): void
|
|||||||
/**
|
/**
|
||||||
* @dataProvider data
|
* @dataProvider data
|
||||||
*/
|
*/
|
||||||
public function test_failed_to_stop_service(string $name): void
|
public function test_disable_service(string $name): void
|
||||||
|
{
|
||||||
|
$this->actingAs($this->user);
|
||||||
|
|
||||||
|
$service = $this->server->services()->where('name', $name)->firstOrFail();
|
||||||
|
|
||||||
|
SSH::fake('Active: inactive');
|
||||||
|
|
||||||
|
$this->get(route('servers.services.disable', [
|
||||||
|
'server' => $this->server,
|
||||||
|
'service' => $service,
|
||||||
|
]))->assertSessionDoesntHaveErrors();
|
||||||
|
|
||||||
|
$service->refresh();
|
||||||
|
|
||||||
|
$this->assertEquals(ServiceStatus::DISABLED, $service->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider data
|
||||||
|
*/
|
||||||
|
public function test_failed_to_disable_service(string $name): void
|
||||||
{
|
{
|
||||||
$this->actingAs($this->user);
|
$this->actingAs($this->user);
|
||||||
|
|
||||||
@ -139,7 +223,7 @@ public function test_failed_to_stop_service(string $name): void
|
|||||||
|
|
||||||
SSH::fake('Active: active');
|
SSH::fake('Active: active');
|
||||||
|
|
||||||
$this->get(route('servers.services.stop', [
|
$this->get(route('servers.services.disable', [
|
||||||
'server' => $this->server,
|
'server' => $this->server,
|
||||||
'service' => $service,
|
'service' => $service,
|
||||||
]))->assertSessionDoesntHaveErrors();
|
]))->assertSessionDoesntHaveErrors();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user