Skip to content

Commit

Permalink
Merge pull request lima-vm#1171 from balajiv113/pid
Browse files Browse the repository at this point in the history
support for driver specific pid files
  • Loading branch information
AkihiroSuda authored Nov 18, 2022
2 parents 8127fbd + cbc6946 commit cd504a4
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions cmd/limactl/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begi
}

func stopInstanceForcibly(inst *store.Instance) {
if inst.QemuPID > 0 {
logrus.Infof("Sending SIGKILL to the %s driver process %d", inst.VMType, inst.QemuPID)
if err := osutil.SysKill(inst.QemuPID, osutil.SigKill); err != nil {
if inst.DriverPID > 0 {
logrus.Infof("Sending SIGKILL to the %s driver process %d", inst.VMType, inst.DriverPID)
if err := osutil.SysKill(inst.DriverPID, osutil.SigKill); err != nil {
logrus.Error(err)
}
} else {
Expand Down
1 change: 1 addition & 0 deletions docs/internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ QEMU:
- `serial.sock`: QEMU serial socket, for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serial.sock`)

VZ:
- `vz.pid`: VZ PID
- `vz-identifier`: Unique machine identifier file for a VM
- `vz-efi`: EFIVariable store file for a VM

Expand Down
2 changes: 1 addition & 1 deletion pkg/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ func Cmdline(cfg Config) (string, []string, error) {

// QEMU process
args = append(args, "-name", "lima-"+cfg.Name)
args = append(args, "-pidfile", filepath.Join(cfg.InstanceDir, filenames.QemuPID))
args = append(args, "-pidfile", filepath.Join(cfg.InstanceDir, filenames.PIDFile(*y.VMType)))

return exe, args, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/qemu/qemu_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (l *LimaQemuDriver) killQEMU(_ context.Context, _ time.Duration, qCmd *exec
}
qWaitErr := <-qWaitCh
logrus.WithError(qWaitErr).Info("QEMU has exited, after killing forcibly")
qemuPIDPath := filepath.Join(l.Instance.Dir, filenames.QemuPID)
qemuPIDPath := filepath.Join(l.Instance.Dir, filenames.PIDFile(*l.Yaml.VMType))
_ = os.RemoveAll(qemuPIDPath)
return qWaitErr
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/store/filenames/filenames.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const (
Kernel = "kernel"
KernelCmdline = "kernel.cmdline"
Initrd = "initrd"
QemuPID = "qemu.pid"
QMPSock = "qmp.sock"
SerialLog = "serial.log"
SerialSock = "serial.sock"
Expand Down Expand Up @@ -66,3 +65,7 @@ const (
// ssh appends 16 bytes of random characters when it first creates the socket:
// https://github.com/openssh/openssh-portable/blob/V_8_7_P1/mux.c#L1271-L1285
const LongestSock = SSHSock + ".1234567890123456"

func PIDFile(name string) string {
return name + ".pid"
}
12 changes: 6 additions & 6 deletions pkg/store/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Instance struct {
Networks []limayaml.Network `json:"network,omitempty"`
SSHLocalPort int `json:"sshLocalPort,omitempty"`
HostAgentPID int `json:"hostAgentPID,omitempty"`
QemuPID int `json:"qemuPID,omitempty"`
DriverPID int `json:"driverPID,omitempty"`
Errors []error `json:"errors,omitempty"`
}

Expand Down Expand Up @@ -121,19 +121,19 @@ func Inspect(instName string) (*Instance, error) {
}
}

inst.QemuPID, err = ReadPIDFile(filepath.Join(instDir, filenames.QemuPID))
inst.DriverPID, err = ReadPIDFile(filepath.Join(instDir, filenames.PIDFile(*y.VMType)))
if err != nil {
inst.Status = StatusBroken
inst.Errors = append(inst.Errors, err)
}

if inst.Status == StatusUnknown {
if inst.HostAgentPID > 0 && inst.QemuPID > 0 {
if inst.HostAgentPID > 0 && inst.DriverPID > 0 {
inst.Status = StatusRunning
} else if inst.HostAgentPID == 0 && inst.QemuPID == 0 {
} else if inst.HostAgentPID == 0 && inst.DriverPID == 0 {
inst.Status = StatusStopped
} else if inst.HostAgentPID > 0 && inst.QemuPID == 0 {
inst.Errors = append(inst.Errors, errors.New("host agent is running but qemu is not"))
} else if inst.HostAgentPID > 0 && inst.DriverPID == 0 {
inst.Errors = append(inst.Errors, errors.New("host agent is running but driver is not"))
inst.Status = StatusBroken
} else {
inst.Errors = append(inst.Errors, fmt.Errorf("%s driver is running but host agent is not", inst.VMType))
Expand Down
2 changes: 1 addition & 1 deletion pkg/vz/vm_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine
case newState := <-machine.StateChangedNotify():
switch newState {
case vz.VirtualMachineStateRunning:
pidFile := filepath.Join(driver.Instance.Dir, filenames.QemuPID)
pidFile := filepath.Join(driver.Instance.Dir, filenames.PIDFile(*driver.Yaml.VMType))
if _, err := os.Stat(pidFile); !errors.Is(err, os.ErrNotExist) {
logrus.Errorf("pidfile %q already exists", pidFile)
errCh <- err
Expand Down

0 comments on commit cd504a4

Please sign in to comment.