Skip to content

Commit 1b260c2

Browse files
authored
Merge pull request #286 from AkihiroSuda/nits-20211004
nits
2 parents bab1029 + 141284e commit 1b260c2

File tree

8 files changed

+57
-27
lines changed

8 files changed

+57
-27
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ Install recent version of QEMU. v6.1.0 or later is recommended.
101101

102102
On ARM hosts, a [patched](https://patchwork.kernel.org/series/548227/mbox/) version of QEMU has to be installed for enabling `-accel hvf` support.
103103

104-
The patch is not merged into the QEMU upstream yet as of QEMU v6.1.0, but already included in [the Homebrew package of QEMU](https://github.com/Homebrew/homebrew-core/commit/5e8eb547) since `6.1.0_1` bottle.
104+
The patch was merged into the master branch on [2021-09-21](https://github.com/qemu/qemu/commit/81ceb36b9) and will be included in QEMU v6.2.0.
105+
106+
The patch is already cherry-picked in [the Homebrew package of QEMU](https://github.com/Homebrew/homebrew-core/commit/5e8eb547) since `6.1.0_1` bottle.
105107

106108
#### Install Lima
107109

cmd/limactl/main.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package main
22

33
import (
44
"errors"
5+
"fmt"
56
"os"
7+
"path/filepath"
68
"strings"
79

810
"github.com/lima-vm/lima/pkg/store/dirnames"
@@ -23,10 +25,30 @@ func main() {
2325
}
2426

2527
func newApp() *cobra.Command {
28+
examplesDir := "$PREFIX/share/doc/lima/examples"
29+
if exe, err := os.Executable(); err == nil {
30+
binDir := filepath.Dir(exe)
31+
prefixDir := filepath.Dir(binDir)
32+
examplesDir = filepath.Join(prefixDir, "share/doc/lima/examples")
33+
}
34+
2635
var rootCmd = &cobra.Command{
27-
Use: "limactl",
28-
Short: "Lima: Linux virtual machines",
29-
Version: strings.TrimPrefix(version.Version, "v"),
36+
Use: "limactl",
37+
Short: "Lima: Linux virtual machines",
38+
Version: strings.TrimPrefix(version.Version, "v"),
39+
Example: fmt.Sprintf(` Start the default instance:
40+
$ limactl start
41+
42+
Open a shell:
43+
$ lima
44+
45+
Run a container:
46+
$ lima nerdctl run -d --name nginx -p 8080:80 nginx:alpine
47+
48+
Stop the default instance:
49+
$ limactl stop
50+
51+
See also example YAMLs: %s`, examplesDir),
3052
SilenceUsage: true,
3153
SilenceErrors: true,
3254
}

cmd/limactl/stop.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"syscall"
1111
"time"
1212

13-
hostagentapi "github.com/lima-vm/lima/pkg/hostagent/api"
14-
"github.com/lima-vm/lima/pkg/networks/reconcile"
13+
hostagentevents "github.com/lima-vm/lima/pkg/hostagent/events"
14+
networks "github.com/lima-vm/lima/pkg/networks/reconcile"
1515
"github.com/lima-vm/lima/pkg/store"
1616
"github.com/lima-vm/lima/pkg/store/filenames"
1717
"github.com/sirupsen/logrus"
@@ -22,7 +22,7 @@ func newStopCommand() *cobra.Command {
2222
var stopCmd = &cobra.Command{
2323
Use: "stop INSTANCE",
2424
Short: "Stop an instance",
25-
Args: cobra.ExactArgs(1),
25+
Args: cobra.MaximumNArgs(1),
2626
RunE: stopAction,
2727
ValidArgsFunction: stopBashComplete,
2828
}
@@ -32,9 +32,9 @@ func newStopCommand() *cobra.Command {
3232
}
3333

3434
func stopAction(cmd *cobra.Command, args []string) error {
35-
instName := args[0]
36-
if instName == "" {
37-
instName = DefaultInstanceName
35+
instName := DefaultInstanceName
36+
if len(args) > 0 {
37+
instName = args[0]
3838
}
3939

4040
inst, err := store.Inspect(instName)
@@ -78,7 +78,7 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begi
7878
defer cancel()
7979

8080
var receivedExitingEvent bool
81-
onEvent := func(ev hostagentapi.Event) bool {
81+
onEvent := func(ev hostagentevents.Event) bool {
8282
if len(ev.Status.Errors) > 0 {
8383
logrus.Errorf("%+v", ev.Status.Errors)
8484
}
@@ -92,7 +92,7 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begi
9292
haStdoutPath := filepath.Join(inst.Dir, filenames.HostAgentStdoutLog)
9393
haStderrPath := filepath.Join(inst.Dir, filenames.HostAgentStderrLog)
9494

95-
if err := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, begin, onEvent); err != nil {
95+
if err := hostagentevents.Watch(ctx2, haStdoutPath, haStderrPath, begin, onEvent); err != nil {
9696
return err
9797
}
9898

docs/internal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Guest agent:
5050

5151
Host agent:
5252
- `ha.pid`: hostagent PID
53-
- `ha.stdout.log`: hostagent stdout (JSON lines, see `pkg/hostagent/api.Events`)
53+
- `ha.stdout.log`: hostagent stdout (JSON lines, see `pkg/hostagent/events.Event`)
5454
- `ha.stderr.log`: hostagent stderr (human-readable messages)
5555

5656
## Lima cache directory (`~/Library/Caches/lima`)

pkg/hostagent/api/api.go renamed to pkg/hostagent/events/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package api
1+
package events
22

33
import (
44
"time"

pkg/hostagent/api/eventwatcher.go renamed to pkg/hostagent/events/watcher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package api
1+
package events
22

33
import (
44
"context"
@@ -10,7 +10,7 @@ import (
1010
"github.com/sirupsen/logrus"
1111
)
1212

13-
func WatchEvents(ctx context.Context, haStdoutPath, haStderrPath string, begin time.Time, onEvent func(Event) bool) error {
13+
func Watch(ctx context.Context, haStdoutPath, haStderrPath string, begin time.Time, onEvent func(Event) bool) error {
1414
haStdoutTail, err := tail.TailFile(haStdoutPath,
1515
tail.Config{
1616
Follow: true,

pkg/hostagent/hostagent.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/hashicorp/go-multierror"
2020
guestagentapi "github.com/lima-vm/lima/pkg/guestagent/api"
2121
guestagentclient "github.com/lima-vm/lima/pkg/guestagent/api/client"
22-
hostagentapi "github.com/lima-vm/lima/pkg/hostagent/api"
22+
"github.com/lima-vm/lima/pkg/hostagent/events"
2323
"github.com/lima-vm/lima/pkg/limayaml"
2424
"github.com/lima-vm/lima/pkg/qemu"
2525
"github.com/lima-vm/lima/pkg/sshutil"
@@ -114,7 +114,7 @@ func New(instName string, stdout, stderr io.Writer, sigintCh chan os.Signal) (*H
114114
return a, nil
115115
}
116116

117-
func (a *HostAgent) emitEvent(ctx context.Context, ev hostagentapi.Event) {
117+
func (a *HostAgent) emitEvent(ctx context.Context, ev events.Event) {
118118
a.eventEncMu.Lock()
119119
defer a.eventEncMu.Unlock()
120120
if ev.Time.IsZero() {
@@ -135,8 +135,8 @@ func logPipeRoutine(l *logrus.Logger, r io.Reader, header string) {
135135

136136
func (a *HostAgent) Run(ctx context.Context) error {
137137
defer func() {
138-
exitingEv := hostagentapi.Event{
139-
Status: hostagentapi.Status{
138+
exitingEv := events.Event{
139+
Status: events.Status{
140140
Exiting: true,
141141
},
142142
}
@@ -177,11 +177,11 @@ func (a *HostAgent) Run(ctx context.Context) error {
177177
if sshLocalPort < 0 {
178178
return fmt.Errorf("invalid ssh local port %d", sshLocalPort)
179179
}
180-
stBase := hostagentapi.Status{
180+
stBase := events.Status{
181181
SSHLocalPort: sshLocalPort,
182182
}
183183
stBooting := stBase
184-
a.emitEvent(ctx, hostagentapi.Event{Status: stBooting})
184+
a.emitEvent(ctx, events.Event{Status: stBooting})
185185

186186
go func() {
187187
stRunning := stBase
@@ -190,7 +190,7 @@ func (a *HostAgent) Run(ctx context.Context) error {
190190
stRunning.Errors = append(stRunning.Errors, haErr.Error())
191191
}
192192
stRunning.Running = true
193-
a.emitEvent(ctx, hostagentapi.Event{Status: stRunning})
193+
a.emitEvent(ctx, events.Event{Status: stRunning})
194194
}()
195195

196196
for {

pkg/start/start.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/lima-vm/lima/pkg/cidata"
13-
hostagentapi "github.com/lima-vm/lima/pkg/hostagent/api"
13+
hostagentevents "github.com/lima-vm/lima/pkg/hostagent/events"
1414
"github.com/lima-vm/lima/pkg/limayaml"
1515
"github.com/lima-vm/lima/pkg/qemu"
1616
"github.com/lima-vm/lima/pkg/store"
@@ -72,10 +72,16 @@ func Start(ctx context.Context, inst *store.Instance) error {
7272
}
7373
// no defer haStderrW.Close()
7474

75-
haCmd := exec.CommandContext(ctx, self,
75+
var args []string
76+
if logrus.GetLevel() >= logrus.DebugLevel {
77+
args = append(args, "--debug")
78+
}
79+
args = append(args,
7680
"hostagent",
7781
"--pidfile", haPIDPath,
7882
inst.Name)
83+
haCmd := exec.CommandContext(ctx, self, args...)
84+
7985
haCmd.Stdout = haStdoutW
8086
haCmd.Stderr = haStderrW
8187

@@ -134,7 +140,7 @@ func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrP
134140
receivedRunningEvent bool
135141
err error
136142
)
137-
onEvent := func(ev hostagentapi.Event) bool {
143+
onEvent := func(ev hostagentevents.Event) bool {
138144
if !printedSSHLocalPort && ev.Status.SSHLocalPort != 0 {
139145
logrus.Infof("SSH Local Port: %d", ev.Status.SSHLocalPort)
140146
printedSSHLocalPort = true
@@ -161,7 +167,7 @@ func watchHostAgentEvents(ctx context.Context, instName, haStdoutPath, haStderrP
161167
return false
162168
}
163169

164-
if xerr := hostagentapi.WatchEvents(ctx2, haStdoutPath, haStderrPath, begin, onEvent); xerr != nil {
170+
if xerr := hostagentevents.Watch(ctx2, haStdoutPath, haStderrPath, begin, onEvent); xerr != nil {
165171
return xerr
166172
}
167173

0 commit comments

Comments
 (0)