Skip to content

Commit

Permalink
Add PID in status output. Check that the process executable is either…
Browse files Browse the repository at this point in the history
… 'hyperkit' or 'com.docker.hyper'. Note, the executable name is limited to 16 bytes long
  • Loading branch information
bensallen committed Dec 23, 2019
1 parent b517e71 commit 147a57f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

- Add VPNKit support

### Start
### Up

- Change permissions on tap and tty, then drop privs to run hyperkit
- Automatically pick a unused tap interface if not specified
Expand All @@ -35,7 +35,7 @@

- Generate a hkmgr.toml

### Stop
### Down

- Prompt when running without a specific VM, asking if all VMs should be stopped to avoid annoyances. Add -y flag to answer via CLI.

Expand Down
8 changes: 7 additions & 1 deletion internal/config/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type VMConfig struct {
Boot Boot `toml:"boot"`
HDD []*HDD `toml:"hdd"`
CDROM []*CDROM `toml:"cdrom"`
PID int
}

// Status is the status of a VM process
Expand Down Expand Up @@ -107,14 +108,19 @@ func (v *VMConfig) Status() Status {
return NotFound
}

v.PID = pid

proc, err := ps.FindProcess(pid)
if err != nil {
return NotFound
}
if proc == nil {
return Stopped
}
return Running
if proc.Executable() == "hyperkit" || proc.Executable() == "com.docker.hyper" {
return Running
}
return Stopped
}

// Kill attempts to kill a VM via the pid file with the specified signal.
Expand Down
4 changes: 2 additions & 2 deletions internal/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func Current(cfg *config.Config, name string, debug bool) error {
if name != "" {
if vm, ok := cfg.VM[name]; ok {
fmt.Printf("%s status is %s\n", name, vm.Status())
fmt.Printf("%s status is %s, PID: %d\n", name, vm.Status(), vm.PID)
} else {
return fmt.Errorf("%s not found in the configuration", name)
}
Expand All @@ -23,7 +23,7 @@ func Current(cfg *config.Config, name string, debug bool) error {
sort.Strings(names)
for _, n := range names {
vm := cfg.VM[n]
fmt.Printf("%s status is %s\n", n, vm.Status())
fmt.Printf("%s status is %s, PID: %d\n", n, vm.Status(), vm.PID)
}
}
return nil
Expand Down

0 comments on commit 147a57f

Please sign in to comment.