- Updated serverplaceholder.blade.php to enhance loading skeletons for server details. - Added navigation breadcrumbs to statistics, subdomain, and system views for better user experience. - Improved loading indicators for CPU, network, memory, and disk charts in statistics.blade.php. - Refined storage.blade.php layout with section dividers and improved drive display, including bus type indicators and quota usage. - Enhanced VNC and Xterm popups with a new header design, loading animations, and reconnect functionality. - Added error handling for VNC and Xterm connections to inform users when unable to connect.
84 lines
2.7 KiB
PHP
84 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Paymenter\Extensions\Servers\Proxmox\Jobs;
|
|
|
|
use App\Helpers\ExtensionHelper;
|
|
use App\Helpers\NotificationHelper;
|
|
use Exception;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Str;
|
|
use Paymenter\Extensions\Servers\Proxmox\Models\Server;
|
|
use Paymenter\Extensions\Servers\Proxmox\Proxmox;
|
|
|
|
class ReinstallJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public int $tries = 5;
|
|
|
|
public int $timeout = 600; // 10 minutes
|
|
|
|
/**
|
|
* Exponential backoff between retries (seconds).
|
|
*/
|
|
public array $backoff = [10, 30, 60, 120, 300];
|
|
|
|
public function __construct(public Server $server) {}
|
|
|
|
public function handle(): void
|
|
{
|
|
$proxmox = new Proxmox;
|
|
|
|
// Stop and delete existing VM if it exists
|
|
try {
|
|
$proxmox->requestAndWait(
|
|
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/status/stop',
|
|
'post',
|
|
['vmid' => $this->server->vm_id],
|
|
$this->server->node->name
|
|
);
|
|
|
|
$proxmox->requestAndWait(
|
|
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id,
|
|
'delete',
|
|
[],
|
|
$this->server->node->name
|
|
);
|
|
} catch (Exception $e) {
|
|
$msg = strtolower($e->getMessage());
|
|
// Allow reinstall to proceed if VM doesn't exist or is already stopped
|
|
if (!str_contains($msg, 'does not exist')
|
|
&& !str_contains($msg, 'not running')
|
|
&& !str_contains($msg, 'already stopped')
|
|
&& !str_contains($msg, 'is not running')) {
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
// Generate a new password
|
|
$password = Str::password(16);
|
|
|
|
// Reinstall server — install() will now use the updated password
|
|
|
|
$settings = array_merge(ExtensionHelper::settingsToArray($this->server->service->product->settings), ExtensionHelper::getServiceProperties($this->server->service));
|
|
|
|
$proxmox->install($this->server, $settings, $password);
|
|
|
|
// Send notification to the user
|
|
NotificationHelper::serverCreatedNotification(
|
|
$this->server->service->user,
|
|
$this->server->service,
|
|
[
|
|
'password' => $password,
|
|
'ip' => $this->server->primaryIpv4?->ip,
|
|
'ipv6' => $this->server->primaryIpv6?->ip,
|
|
'hostname' => $this->server->hostname,
|
|
]
|
|
);
|
|
}
|
|
}
|