Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Actions/Server/InstallServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function install(): void
foreach ($services as $service) {
$currentProgress += $progressPerService;
$this->progress($currentProgress, 'installing- '.$service->name);

$service->newLog();

$service->handler()->install();
$service->update(['status' => ServiceStatus::READY]);
if ($service->type == 'php') {
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/API/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function index(Project $project, Server $server): ResourceCollection

$this->validateRoute($project, $server);

return ServiceResource::collection($server->services()->simplePaginate(25));
return ServiceResource::collection($server->services()->with('log')->simplePaginate(25));
}

#[Get('{service}', name: 'api.projects.servers.services.show', middleware: 'ability:read')]
Expand All @@ -37,6 +37,8 @@ public function show(Project $project, Server $server, Service $service): Servic

$this->validateRoute($project, $server, $service);

$service->load('log');

return new ServiceResource($service);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function index(Server $server): Response
{
$this->authorize('viewAny', [Service::class, $server]);

$services = $server->services()->simplePaginate(config('web.pagination_size'));
$services = $server->services()->with('log')->simplePaginate(config('web.pagination_size'));

return Inertia::render('services/index', [
'services' => ServiceResource::collection($services),
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/ServiceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function toArray(Request $request): array
'status_color' => $this->status->getColor(),
'icon' => config('core.service_icons')[$this->name] ?? '',
'is_default' => $this->is_default,
'log' => $this->log ? new ServerLogResource($this->log) : null,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
Expand Down
3 changes: 3 additions & 0 deletions app/Jobs/Service/InstallJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public function handle(): void
{
$this->run("server-{$this->service->server_id}", function () {
Log::info("Installing service ID {$this->service->id} on server ID {$this->service->server_id}");

$this->service->newLog();

$this->service->handler()->install();
$this->service->status = ServiceStatus::READY;
$this->service->installed_version = $this->service->handler()->version();
Expand Down
26 changes: 26 additions & 0 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

/**
* @property int $server_id
* @property ?int $log_id
* @property string $type
* @property array<string, mixed> $type_data
* @property string $name
Expand All @@ -28,6 +29,7 @@
* @property ServiceStatus $status
* @property bool $is_default
* @property Server $server
* @property ?ServerLog $log
*/
class Service extends AbstractModel
{
Expand All @@ -36,6 +38,7 @@ class Service extends AbstractModel

protected $fillable = [
'server_id',
'log_id',
'type',
'type_data',
'name',
Expand All @@ -49,6 +52,7 @@ class Service extends AbstractModel

protected $casts = [
'server_id' => 'integer',
'log_id' => 'integer',
'type_data' => 'json',
'is_default' => 'boolean',
'status' => ServiceStatus::class,
Expand All @@ -62,6 +66,14 @@ public function server(): BelongsTo
return $this->belongsTo(Server::class);
}

/**
* @return BelongsTo<ServerLog, covariant $this>
*/
public function log(): BelongsTo
{
return $this->belongsTo(ServerLog::class, 'log_id');
}

public function handler(): ServiceInterface|Webserver|PHP|Firewall|\App\Services\Database\Database|ProcessManager
{
$name = $this->name;
Expand Down Expand Up @@ -116,4 +128,18 @@ public function disable(): void
{
$this->handler()->unit() && app(Manage::class)->disable($this);
}

public function newLog(): ServerLog
{

$serverLog = ServerLog::newLog(
$this->server,
'install-'.$this->name.'-'.$this->version
);
$serverLog->save();
$this->log_id = $serverLog->id;
$this->save();

return $serverLog;
}
}
4 changes: 3 additions & 1 deletion app/Services/Database/AbstractDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public function install(): void
{
$version = str_replace('.', '', $this->service->version);
$command = view($this->getScriptView('install-'.$version));
$this->service->server->ssh()->exec($command, 'install-'.$this->service->name.'-'.$version);
$this->service->server->ssh()
->setLog($this->service->log)
->exec($command, 'install-'.$this->service->name.'-'.$version);
$status = $this->service->server->systemd()->status($this->unit());
$this->service->validateInstall($status);
$this->service->server->os()->cleanup();
Expand Down
10 changes: 6 additions & 4 deletions app/Services/Firewall/Ufw.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public function install(): void
{
$this->createBasicFirewallRules();

$this->service->server->ssh()->exec(
view('ssh.services.firewall.ufw.install-ufw'),
'install-ufw'
);
$this->service->server->ssh()
->setLog($this->service->log)
->exec(
view('ssh.services.firewall.ufw.install-ufw'),
'install-ufw'
);
event('service.installed', $this->service);
$this->service->server->os()->cleanup();
}
Expand Down
18 changes: 10 additions & 8 deletions app/Services/Monitoring/VitoAgent/VitoAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ public function install(): void
$this->service->save();
$this->service->refresh();

$this->service->server->ssh()->exec(
view('ssh.services.monitoring.vito-agent.install', [
'downloadUrl' => $downloadUrl,
'configUrl' => $this->data()['url'],
'configSecret' => $this->data()['secret'],
]),
'install-vito-agent'
);
$this->service->server->ssh()
->setLog($this->service->log)
->exec(
view('ssh.services.monitoring.vito-agent.install', [
'downloadUrl' => $downloadUrl,
'configUrl' => $this->data()['url'],
'configSecret' => $this->data()['secret'],
]),
'install-vito-agent'
);
$status = $this->service->server->systemd()->status($this->unit());
event('service.installed', $this->service);
$this->service->validateInstall($status);
Expand Down
16 changes: 9 additions & 7 deletions app/Services/NodeJS/NodeJS.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ public function uninstall(): void
if ($this->service->server->services()->where('type', 'nodejs')->count() > 1) {
return;
}
$this->service->server->ssh()->exec(
view('ssh.services.nodejs.uninstall-nodejs', [
'version' => $this->service->version,
'default' => $this->service->is_default,
]),
'uninstall-nodejs-'.$this->service->version
);
$this->service->server->ssh()
->setLog($this->service->log)
->exec(
view('ssh.services.nodejs.uninstall-nodejs', [
'version' => $this->service->version,
'default' => $this->service->is_default,
]),
'uninstall-nodejs-'.$this->service->version
);
event('service.uninstalled', $this->service);
$this->service->server->os()->cleanup();
}
Expand Down
16 changes: 9 additions & 7 deletions app/Services/PHP/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ function (string $attribute, mixed $value, Closure $fail): void {
public function install(): void
{
$server = $this->service->server;
$server->ssh()->exec(
view('ssh.services.php.install-php', [
'version' => $this->service->version,
'user' => $server->getSshUser(),
]),
'install-php-'.$this->service->version
);
$server->ssh()
->setLog($this->service->log)
->exec(
view('ssh.services.php.install-php', [
'version' => $this->service->version,
'user' => $server->getSshUser(),
]),
'install-php-'.$this->service->version
);
$this->installComposer();
event('service.installed', $this->service);
$this->service->server->os()->cleanup();
Expand Down
10 changes: 6 additions & 4 deletions app/Services/ProcessManager/Supervisor.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public function unit(): string
*/
public function install(): void
{
$this->service->server->ssh()->exec(
view('ssh.services.process-manager.supervisor.install-supervisor'),
'install-supervisor'
);
$this->service->server->ssh()
->setLog($this->service->log)
->exec(
view('ssh.services.process-manager.supervisor.install-supervisor'),
'install-supervisor'
);
event('service.installed', $this->service);
$this->service->server->os()->cleanup();
}
Expand Down
10 changes: 6 additions & 4 deletions app/Services/Redis/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ function (string $attribute, mixed $value, Closure $fail): void {
*/
public function install(): void
{
$this->service->server->ssh()->exec(
view('ssh.services.redis.install'),
'install-redis'
);
$this->service->server->ssh()
->setLog($this->service->log)
->exec(
view('ssh.services.redis.install'),
'install-redis'
);
$status = $this->service->server->systemd()->status($this->unit());
$this->service->validateInstall($status);
event('service.installed', $this->service);
Expand Down
10 changes: 6 additions & 4 deletions app/Services/Valkey/Valkey.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ function (string $attribute, mixed $value, Closure $fail): void {
*/
public function install(): void
{
$this->service->server->ssh()->exec(
view('ssh.services.valkey.install'),
'install-valkey'
);
$this->service->server->ssh()
->setLog($this->service->log)
->exec(
view('ssh.services.valkey.install'),
'install-valkey'
);
$status = $this->service->server->systemd()->status($this->unit());
$this->service->validateInstall($status);
event('service.installed', $this->service);
Expand Down
10 changes: 6 additions & 4 deletions app/Services/Webserver/Caddy.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public function unit(): string
*/
public function install(): void
{
$this->service->server->ssh()->exec(
view('ssh.services.webserver.caddy.install-caddy'),
'install-caddy'
);
$this->service->server->ssh()
->setLog($this->service->log)
->exec(
view('ssh.services.webserver.caddy.install-caddy'),
'install-caddy'
);

$this->service->server->ssh()->write(
'/etc/caddy/Caddyfile',
Expand Down
10 changes: 6 additions & 4 deletions app/Services/Webserver/Nginx.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public function unit(): string
*/
public function install(): void
{
$this->service->server->ssh()->exec(
view('ssh.services.webserver.nginx.install-nginx'),
'install-nginx'
);
$this->service->server->ssh()
->setLog($this->service->log)
->exec(
view('ssh.services.webserver.nginx.install-nginx'),
'install-nginx'
);

$this->service->server->ssh()->write(
'/etc/nginx/nginx.conf',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('services', function (Blueprint $table) {
$table->unsignedBigInteger('log_id')->nullable()->after('server_id');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('services', function (Blueprint $table) {
$table->dropColumn('log_id');
});
}
};
7 changes: 7 additions & 0 deletions resources/js/pages/services/components/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Uninstall from '@/pages/services/components/uninstall';
import { Action } from '@/pages/services/components/action';
import Version from './version';
import ConfigFile from './config-file';
import InstallationLog from './installation-log';

export const columns: ColumnDef<Service>[] = [
{
Expand Down Expand Up @@ -73,6 +74,12 @@ export const columns: ColumnDef<Service>[] = [
))}
</>
)}
{row.original.log && (
<>
<DropdownMenuSeparator />
<InstallationLog service={row.original} />
</>
)}
<DropdownMenuSeparator />
<Uninstall service={row.original} />
</DropdownMenuContent>
Expand Down
Loading