From 8b985654ef8197a5d4687a8b4757e58ba1513c41 Mon Sep 17 00:00:00 2001 From: yusing Date: Wed, 28 Jan 2026 22:41:11 +0800 Subject: [PATCH] fix(proxmox): improve journalctl with log tailing fallback for non-systemd systems - Format tail command with fallback retry logic - Add /var/log/messages fallback when no services specified Improves log viewing reliability on systems without systemd support. --- internal/proxmox/command_common.go | 5 +++-- internal/proxmox/lxc_command.go | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/proxmox/command_common.go b/internal/proxmox/command_common.go index f3404ef4..e48549d9 100644 --- a/internal/proxmox/command_common.go +++ b/internal/proxmox/command_common.go @@ -31,14 +31,15 @@ func formatTail(files []string, limit int) (string, error) { } } var command strings.Builder - command.WriteString("tail -f -q --retry ") + command.WriteString("tail -f -q ") for _, file := range files { fmt.Fprintf(&command, " %q ", file) } if limit > 0 { fmt.Fprintf(&command, " -n %d", limit) } - return command.String(), nil + // try --retry first, if it fails, try the command again + return fmt.Sprintf("sh -c '%s --retry 2>/dev/null || %s'", command.String(), command.String()), nil } func formatJournalctl(services []string, limit int) (string, error) { diff --git a/internal/proxmox/lxc_command.go b/internal/proxmox/lxc_command.go index f0c82fab..0259eff9 100644 --- a/internal/proxmox/lxc_command.go +++ b/internal/proxmox/lxc_command.go @@ -39,6 +39,8 @@ func (n *Node) LXCCommand(ctx context.Context, vmid int, command string) (io.Rea // LXCJournalctl streams journalctl output for the given service. // +// On non systemd systems, it will tail /var/log/messages as fallback. +// // If services are not empty, it will be used to filter the output by service. // If limit is greater than 0, it will be used to limit the number of lines of output. func (n *Node) LXCJournalctl(ctx context.Context, vmid int, services []string, limit int) (io.ReadCloser, error) { @@ -46,6 +48,11 @@ func (n *Node) LXCJournalctl(ctx context.Context, vmid int, services []string, l if err != nil { return nil, err } + if len(services) == 0 { + // add /var/log/messages fallback for non systemd systems + // in tail command, try --retry first, if it fails, try the command again + command = fmt.Sprintf("sh -c '%s 2>/dev/null || tail -f -q --retry /var/log/messages 2>/dev/null || tail -f -q /var/log/messages'", command) + } return n.LXCCommand(ctx, vmid, command) }