mailwolt/app/Console/Commands/MailwoltRestart.php

37 lines
1.0 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MailwoltRestart extends Command
{
protected $signature = 'mailwolt:restart-services';
protected $description = 'Restart or reload MailWolt-related system services';
public function handle(): int
{
$units = config('mailwolt.units', []);
foreach ($units as $u) {
$unit = rtrim($u['name'] ?? '', '.service') . '.service';
$action = $u['action'] ?? 'try-reload-or-restart';
$cmd = sprintf('sudo -n /usr/bin/systemctl %s %s', escapeshellarg($action), escapeshellarg($unit));
$this->info("{$unit} ({$action})");
exec($cmd . ' 2>&1', $out, $rc);
foreach ($out as $line) {
$this->line(" $line");
}
if ($rc !== 0) {
$this->warn(" [!] Fehler beim Neustart von {$unit} (rc={$rc})");
} else {
$this->line(" [✓] Erfolgreich");
}
}
return self::SUCCESS;
}
}