Files
ladill-servers/app/Services/Mail/MailServerNfsService.php
T
isaaccladandCursor b6c8ac343f Extract Ladill Servers as standalone app at servers.ladill.com.
VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-06 19:18:30 +00:00

59 lines
1.6 KiB
PHP

<?php
namespace App\Services\Mail;
use App\Models\EmailServer;
use Illuminate\Support\Facades\Log;
class MailServerNfsService
{
public function __construct(
private MailServerSshExecutor $ssh,
private EmailServerPoolService $pool,
) {}
/**
* Allow pool extension IPs on the primary NFS export.
*/
public function refreshPrimaryExports(EmailServer $primary): void
{
$primary = $primary->poolRoot();
if (! $primary->isPrimary() || ! $this->ssh->canConnect($primary)) {
return;
}
$clientIps = $this->pool->poolMembers($primary)
->filter(fn (EmailServer $m) => $m->isExtension())
->pluck('ip_address')
->filter()
->unique()
->values()
->all();
if ($clientIps === []) {
return;
}
$script = resource_path('infrastructure/scripts/nfs-refresh-exports.sh');
$replacements = [
'__VMAIL_ROOT__' => rtrim((string) ($primary->pool_vmail_root ?: config('infrastructure.mail_stack.vmail_root', '/var/vmail')), '/'),
'__NEW_CLIENTS__' => implode(' ', $clientIps),
];
try {
$this->ssh->uploadAndRunScript(
$primary,
'/tmp/ladill-nfs-refresh-exports.sh',
$script,
$replacements,
);
} catch (\Throwable $e) {
Log::warning('Failed to refresh NFS exports on primary mail server', [
'primary_id' => $primary->id,
'error' => $e->getMessage(),
]);
}
}
}