fix: flush log file, show last lines in error output

This commit is contained in:
admin 2026-08-01 16:34:48 +00:00
parent b86d9d3604
commit 5a0cfe92e1

View file

@ -146,11 +146,23 @@ http {
if err == nil { if err == nil {
setupCmd.Stdout = logFile setupCmd.Stdout = logFile
setupCmd.Stderr = logFile setupCmd.Stderr = logFile
defer logFile.Close()
} }
runErr := setupCmd.Run()
if err := setupCmd.Run(); err != nil { if logFile != nil {
return fmt.Errorf("installation failed — check %s/install.log: %w", workDir, err) logFile.Close()
}
if runErr != nil {
// Read the log for the error message
if data, err := os.ReadFile(filepath.Join(workDir, "install.log")); err == nil && len(data) > 0 {
lines := strings.Split(string(data), "\n")
// Print last few lines as the error
start := len(lines) - 5
if start < 0 {
start = 0
}
return fmt.Errorf("%s", strings.Join(lines[start:], "\n"))
}
return fmt.Errorf("installation failed (exit %v) — check %s/install.log", runErr, workDir)
} }
// 6. Enable and start systemd service // 6. Enable and start systemd service