diff --git a/README.md b/README.md index 2270493bf79..9761fc38efd 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ Lima launches Linux virtual machines with automatic file sharing, port forwardin Lima can be considered as a some sort of unofficial "macOS subsystem for Linux", or "containerd for Mac". Lima is expected to be used on macOS hosts, but can be used on Linux hosts as well. -It may work on NetBSD and Windows hosts as well. ✅ Automatic file sharing diff --git a/cmd/limactl/start.go b/cmd/limactl/start.go index e4e7a121ce8..c37174e7045 100644 --- a/cmd/limactl/start.go +++ b/cmd/limactl/start.go @@ -13,6 +13,7 @@ import ( "github.com/AkihiroSuda/lima/pkg/start" "github.com/AkihiroSuda/lima/pkg/store" "github.com/AkihiroSuda/lima/pkg/store/filenames" + "github.com/AlecAivazis/survey/v2" "github.com/containerd/containerd/identifiers" "github.com/mattn/go-isatty" "github.com/norouter/norouter/cmd/norouter/editorcmd" @@ -94,14 +95,21 @@ func loadOrCreateInstance(clicontext *cli.Context) (*store.Instance, error) { } if clicontext.Bool("tty") { - yBytes, err = openEditor(clicontext, instName, yBytes) + answerOpenEditor, err := askWhetherToOpenEditor(instName) if err != nil { - return nil, err + logrus.WithError(err).Warn("Failed to open TUI") + answerOpenEditor = false } - if len(yBytes) == 0 { - logrus.Info("Aborting, as requested by saving the file with empty content") - os.Exit(0) - return nil, errors.New("should not reach here") + if answerOpenEditor { + yBytes, err = openEditor(clicontext, instName, yBytes) + if err != nil { + return nil, err + } + if len(yBytes) == 0 { + logrus.Info("Aborting, as requested by saving the file with empty content") + os.Exit(0) + return nil, errors.New("should not reach here") + } } } else { logrus.Info("Terminal is not available, proceeding without opening an editor") @@ -129,6 +137,32 @@ func loadOrCreateInstance(clicontext *cli.Context) (*store.Instance, error) { return store.Inspect(instName) } +func askWhetherToOpenEditor(name string) (bool, error) { + var ans string + prompt := &survey.Select{ + Message: fmt.Sprintf("Creating an instance %q", name), + Options: []string{ + "Proceed with the default configuration", + "Open an editor to override the configuration", + "Exit", + }, + } + if err := survey.AskOne(prompt, &ans); err != nil { + return false, err + } + switch ans { + case prompt.Options[0]: + return false, nil + case prompt.Options[1]: + return true, nil + case prompt.Options[2]: + os.Exit(0) + return false, errors.New("should not reach here") + default: + return false, errors.Errorf("unexpected answer %q", ans) + } +} + // openEditor opens an editor, and returns the content (not path) of the modified yaml. // // openEditor returns nil when the file was saved as an empty file, optionally with whitespaces. diff --git a/cmd/limactl/stop.go b/cmd/limactl/stop.go index 533cd97c2c1..5d3d9adcc53 100644 --- a/cmd/limactl/stop.go +++ b/cmd/limactl/stop.go @@ -59,16 +59,17 @@ func stopInstanceGracefully(inst *store.Instance) error { return errors.Errorf("expected status %q, got %q", store.StatusRunning, inst.Status) } + begin := time.Now() // used for logrus propagation logrus.Infof("Sending SIGINT to hostagent process %d", inst.HostAgentPID) if err := syscall.Kill(inst.HostAgentPID, syscall.SIGINT); err != nil { logrus.Error(err) } logrus.Info("Waiting for the host agent and the qemu processes to shut down") - return waitForHostAgentTermination(context.TODO(), inst) + return waitForHostAgentTermination(context.TODO(), inst, begin) } -func waitForHostAgentTermination(ctx context.Context, inst *store.Instance) error { +func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begin time.Time) error { ctx2, cancel := context.WithTimeout(ctx, 3*time.Minute) defer cancel() @@ -87,7 +88,7 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance) erro haStdoutPath := filepath.Join(inst.Dir, filenames.HostAgentStdoutLog) haStderrPath := filepath.Join(inst.Dir, filenames.HostAgentStderrLog) - if err := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, onEvent); err != nil { + if err := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, begin, onEvent); err != nil { return err } diff --git a/go.mod b/go.mod index 7510686ee4a..295bf8a0621 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.16 require ( github.com/AkihiroSuda/sshocker v0.1.1-0.20210510144941-56aa3c7472b0 + github.com/AlecAivazis/survey/v2 v2.2.12 github.com/alessio/shellescape v1.4.1 github.com/containerd/containerd v1.5.2 github.com/containerd/continuity v0.1.0 diff --git a/go.sum b/go.sum index 20ce5839e51..ee821b01ff6 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/AkihiroSuda/sshocker v0.1.1-0.20210510144941-56aa3c7472b0 h1:3wgWVUj7BBfqekwj8muvFjGsLEo0Qga6FHhKL1yitEY= github.com/AkihiroSuda/sshocker v0.1.1-0.20210510144941-56aa3c7472b0/go.mod h1:85HSbV+AEm8Q/sbrx69Q4GQ9MT9OccwnH0ITcOWfO3Q= +github.com/AlecAivazis/survey/v2 v2.2.12 h1:5a07y93zA6SZ09gOa9wLVLznF5zTJMQ+pJ3cZK4IuO8= +github.com/AlecAivazis/survey/v2 v2.2.12/go.mod h1:6d4saEvBsfSHXeN1a5OA5m2+HJ2LuVokllnC77pAIKI= github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest v10.8.1+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= @@ -76,6 +78,8 @@ github.com/Microsoft/hcsshim v0.8.16/go.mod h1:o5/SZqmR7x9JNKsW3pu+nqHm0MF8vbA+V github.com/Microsoft/hcsshim/test v0.0.0-20201218223536-d3e5debf77da/go.mod h1:5hlzMzRKMLyo42nCZ9oml8AdTlq/0cvIaBv6tK1RehU= github.com/Microsoft/hcsshim/test v0.0.0-20210227013316-43a75bb4edd3/go.mod h1:mw7qgWloBUl75W/gVH3cQszUg1+gUITj7D6NY7ywVnY= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= +github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw= +github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= @@ -427,6 +431,8 @@ github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9 github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ= +github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -448,6 +454,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -466,6 +474,8 @@ github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.4-0.20190131011033-7dc38fb350b1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/pty v1.1.5 h1:hyz3dwM5QLc1Rfoz4FuWJQG5BN7tc6K1MndAUnGpQr4= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -477,7 +487,10 @@ github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7 github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho= github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a/go.mod h1:M1qoD/MqPgTZIk0EWKB38wE28ACRfVcn+cU08jyArI0= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA= github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= @@ -485,6 +498,8 @@ github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mibk/dupl v1.0.0/go.mod h1:pCr4pNxxIbFGvtyCOi0c7LVjmV6duhKWV+ex5vh38ME= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= @@ -642,6 +657,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v0.0.0-20180303142811-b89eecf5ca5d/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -716,6 +732,7 @@ golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -835,6 +852,7 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -842,6 +860,7 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190522044717-8097e1b27ff5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190530182044-ad28b68e88f1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/pkg/hostagent/api/eventwatcher.go b/pkg/hostagent/api/eventwatcher.go index 124219f4283..7054629603d 100644 --- a/pkg/hostagent/api/eventwatcher.go +++ b/pkg/hostagent/api/eventwatcher.go @@ -10,8 +10,7 @@ import ( "github.com/sirupsen/logrus" ) -func WatchEvents(ctx context.Context, haStdoutPath, haStderrPath string, onEvent func(Event) bool) error { - begin := time.Now() +func WatchEvents(ctx context.Context, haStdoutPath, haStderrPath string, begin time.Time, onEvent func(Event) bool) error { haStdoutTail, err := tail.TailFile(haStdoutPath, tail.Config{ Follow: true, diff --git a/pkg/logrusutil/logrusutil.go b/pkg/logrusutil/logrusutil.go index c22ca73f8a7..3703e7c9afe 100644 --- a/pkg/logrusutil/logrusutil.go +++ b/pkg/logrusutil/logrusutil.go @@ -8,6 +8,8 @@ import ( "github.com/sirupsen/logrus" ) +const epsilon = 1 * time.Second + // PropagateJSON propagates JSONFormatter lines. // // PanicLevel and FatalLevel are converted to ErrorLevel. @@ -24,7 +26,7 @@ func PropagateJSON(logger *logrus.Logger, jsonLine []byte, header string, begin if err := json.Unmarshal(jsonLine, &j); err != nil { goto fallback } - if !j.Time.IsZero() && !begin.IsZero() && begin.After(j.Time) { + if !j.Time.IsZero() && !begin.IsZero() && begin.After(j.Time.Add(epsilon)) { return } lv, err = logrus.ParseLevel(j.Level) diff --git a/pkg/start/start.go b/pkg/start/start.go index dbfefd19a10..6f474a5b85c 100644 --- a/pkg/start/start.go +++ b/pkg/start/start.go @@ -80,6 +80,8 @@ func Start(ctx context.Context, inst *store.Instance) error { haCmd.Stdout = haStdoutW haCmd.Stderr = haStderrW + begin := time.Now() // used for logrus propagation + if err := haCmd.Start(); err != nil { return err } @@ -88,7 +90,7 @@ func Start(ctx context.Context, inst *store.Instance) error { return err } - return watchHostAgentEvents(ctx, inst.Name, haStdoutPath, haStderrPath) + return watchHostAgentEvents(ctx, inst.Name, haStdoutPath, haStderrPath, begin) // leave the hostagent process running } @@ -106,7 +108,7 @@ func waitHostAgentStart(ctx context.Context, haPIDPath, haStderrPath string) err } } -func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrPath string) error { +func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrPath string, begin time.Time) error { ctx2, cancel := context.WithTimeout(ctx, 10*time.Minute) defer cancel() @@ -142,7 +144,7 @@ func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrP return false } - if xerr := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, onEvent); xerr != nil { + if xerr := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, begin, onEvent); xerr != nil { return xerr } diff --git a/pkg/store/store.go b/pkg/store/store.go index d3b2f420e01..55a5fbaf573 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -65,9 +65,6 @@ func InstanceDir(name string) (string, error) { // LoadYAMLByFilePath loads and validates the yaml. func LoadYAMLByFilePath(filePath string) (*limayaml.LimaYAML, error) { - if _, err := os.Stat(filePath); err != nil { - return nil, err - } yContent, err := os.ReadFile(filePath) if err != nil { return nil, err