*/ public function listServices(bool $all = false): array { $command = Command::fromArray([ 'systemctl', 'list-units', '--type=service', '--no-pager', '--no-legend', ]); if ($all) { $command = Command::fromArray([ 'systemctl', 'list-units', '--type=service', '--all', '--no-pager', '--no-legend', ]); } $result = $this->process->run($command); if (! $result->isSuccess()) { return []; } $services = []; $lines = explode("\n", trim($result->stdout)); foreach ($lines as $line) { if (empty(trim($line))) { continue; } $parts = preg_split('/\s+/', $line, 6); if (count($parts) < 5) { continue; } $name = $parts[0]; $status = $parts[3] ?? 'unknown'; $active = ($parts[3] ?? '') === 'active'; $services[] = [ 'name' => $name, 'status' => $status, 'active' => $active, ]; } return $services; } /** * Gibt den Status eines Services zurück. */ public function getServiceStatus(string $service): ?array { $command = Command::fromArray([ 'systemctl', 'status', $service, '--no-pager', ]); $result = $this->process->run($command); if (! $result->isSuccess()) { return null; } // Parse status output $lines = explode("\n", $result->stdout); $status = [ 'name' => $service, 'active' => false, 'enabled' => false, ]; foreach ($lines as $line) { if (strpos($line, 'Active:') !== false) { $status['active'] = strpos($line, 'active') !== false; } if (strpos($line, 'Loaded:') !== false) { $status['enabled'] = strpos($line, 'enabled') !== false; } } return $status; } /** * Startet einen Service. */ public function startService(string $service): bool { $result = $this->process->run( Command::fromArray(['systemctl', 'start', $service]) ); return $result->isSuccess(); } /** * Stoppt einen Service. */ public function stopService(string $service): bool { $result = $this->process->run( Command::fromArray(['systemctl', 'stop', $service]) ); return $result->isSuccess(); } /** * Startet einen Service neu. */ public function restartService(string $service): bool { $result = $this->process->run( Command::fromArray(['systemctl', 'restart', $service]) ); return $result->isSuccess(); } /** * Aktiviert einen Service. */ public function enableService(string $service): bool { $result = $this->process->run( Command::fromArray(['systemctl', 'enable', $service]) ); return $result->isSuccess(); } /** * Deaktiviert einen Service. */ public function disableService(string $service): bool { $result = $this->process->run( Command::fromArray(['systemctl', 'disable', $service]) ); return $result->isSuccess(); } /** * Gibt fehlgeschlagene Services zurück. * * @return array */ public function getFailedServices(): array { $command = Command::fromArray([ 'systemctl', 'list-units', '--type=service', '--state=failed', '--no-pager', '--no-legend', ]); $result = $this->process->run($command); if (! $result->isSuccess()) { return []; } $failed = []; $lines = explode("\n", trim($result->stdout)); foreach ($lines as $line) { if (empty(trim($line))) { continue; } $parts = preg_split('/\s+/', $line); if (! empty($parts[0])) { $failed[] = $parts[0]; } } return $failed; } }