platform/machine/aws: merge pre/post-termination console logs
GetConsoleOutput only returns 64 KB, which is not quite enough for a
complete boot + shutdown cycle. If we have two sets of logs, merge them.
@@ -18,6 +18,7 @@ import (
"fmt"
"os"
"path/filepath"
+ "strings"
"time"
"github.com/aws/aws-sdk-go/service/ec2"
@@ -117,6 +118,20 @@ func (am *machine) saveConsole(origConsole string) error {
return err
}
+ // merge the two logs
+ overlapLen := 100
+ if len(am.console) < overlapLen {
+ overlapLen = len(am.console)
+ }
+ origIdx := strings.LastIndex(origConsole, am.console[0:overlapLen])
+ if origIdx != -1 {
+ // overlap
+ am.console = origConsole[0:origIdx] + am.console
+ } else if origConsole != "" {
+ // two logs with no overlap; add scissors
+ am.console = origConsole + "\n\n8<------------------------\n\n" + am.console
+ }
+
path := filepath.Join(am.dir, "console.txt")
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
