fix: flush log file, show last lines in error output
This commit is contained in:
parent
b86d9d3604
commit
5a0cfe92e1
1 changed files with 16 additions and 4 deletions
|
|
@ -146,11 +146,23 @@ http {
|
|||
if err == nil {
|
||||
setupCmd.Stdout = logFile
|
||||
setupCmd.Stderr = logFile
|
||||
defer logFile.Close()
|
||||
}
|
||||
|
||||
if err := setupCmd.Run(); err != nil {
|
||||
return fmt.Errorf("installation failed — check %s/install.log: %w", workDir, err)
|
||||
runErr := setupCmd.Run()
|
||||
if logFile != nil {
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue