Skip to content

Commit 21b7cb0

Browse files
committed
start: make sure to print "Starting QEMU" logs
Signed-off-by: Akihiro Suda <[email protected]>
1 parent 89a7ab6 commit 21b7cb0

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

cmd/limactl/stop.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ func stopInstanceGracefully(inst *store.Instance) error {
5959
return errors.Errorf("expected status %q, got %q", store.StatusRunning, inst.Status)
6060
}
6161

62+
begin := time.Now() // used for logrus propagation
6263
logrus.Infof("Sending SIGINT to hostagent process %d", inst.HostAgentPID)
6364
if err := syscall.Kill(inst.HostAgentPID, syscall.SIGINT); err != nil {
6465
logrus.Error(err)
6566
}
6667

6768
logrus.Info("Waiting for the host agent and the qemu processes to shut down")
68-
return waitForHostAgentTermination(context.TODO(), inst)
69+
return waitForHostAgentTermination(context.TODO(), inst, begin)
6970
}
7071

71-
func waitForHostAgentTermination(ctx context.Context, inst *store.Instance) error {
72+
func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begin time.Time) error {
7273
ctx2, cancel := context.WithTimeout(ctx, 3*time.Minute)
7374
defer cancel()
7475

@@ -87,7 +88,7 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance) erro
8788
haStdoutPath := filepath.Join(inst.Dir, filenames.HostAgentStdoutLog)
8889
haStderrPath := filepath.Join(inst.Dir, filenames.HostAgentStderrLog)
8990

90-
if err := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, onEvent); err != nil {
91+
if err := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, begin, onEvent); err != nil {
9192
return err
9293
}
9394

pkg/hostagent/api/eventwatcher.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010
"github.com/sirupsen/logrus"
1111
)
1212

13-
func WatchEvents(ctx context.Context, haStdoutPath, haStderrPath string, onEvent func(Event) bool) error {
14-
begin := time.Now()
13+
func WatchEvents(ctx context.Context, haStdoutPath, haStderrPath string, begin time.Time, onEvent func(Event) bool) error {
1514
haStdoutTail, err := tail.TailFile(haStdoutPath,
1615
tail.Config{
1716
Follow: true,

pkg/logrusutil/logrusutil.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/sirupsen/logrus"
99
)
1010

11+
const epsilon = 1 * time.Second
12+
1113
// PropagateJSON propagates JSONFormatter lines.
1214
//
1315
// PanicLevel and FatalLevel are converted to ErrorLevel.
@@ -24,7 +26,7 @@ func PropagateJSON(logger *logrus.Logger, jsonLine []byte, header string, begin
2426
if err := json.Unmarshal(jsonLine, &j); err != nil {
2527
goto fallback
2628
}
27-
if !j.Time.IsZero() && !begin.IsZero() && begin.After(j.Time) {
29+
if !j.Time.IsZero() && !begin.IsZero() && begin.After(j.Time.Add(epsilon)) {
2830
return
2931
}
3032
lv, err = logrus.ParseLevel(j.Level)

pkg/start/start.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func Start(ctx context.Context, inst *store.Instance) error {
8080
haCmd.Stdout = haStdoutW
8181
haCmd.Stderr = haStderrW
8282

83+
begin := time.Now() // used for logrus propagation
84+
8385
if err := haCmd.Start(); err != nil {
8486
return err
8587
}
@@ -88,7 +90,7 @@ func Start(ctx context.Context, inst *store.Instance) error {
8890
return err
8991
}
9092

91-
return watchHostAgentEvents(ctx, inst.Name, haStdoutPath, haStderrPath)
93+
return watchHostAgentEvents(ctx, inst.Name, haStdoutPath, haStderrPath, begin)
9294
// leave the hostagent process running
9395
}
9496

@@ -106,7 +108,7 @@ func waitHostAgentStart(ctx context.Context, haPIDPath, haStderrPath string) err
106108
}
107109
}
108110

109-
func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrPath string) error {
111+
func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrPath string, begin time.Time) error {
110112
ctx2, cancel := context.WithTimeout(ctx, 10*time.Minute)
111113
defer cancel()
112114

@@ -142,7 +144,7 @@ func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrP
142144
return false
143145
}
144146

145-
if xerr := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, onEvent); xerr != nil {
147+
if xerr := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, begin, onEvent); xerr != nil {
146148
return xerr
147149
}
148150

0 commit comments

Comments
 (0)