Skip to content

Commit cbc6946

Browse files
committed
support for driver specific pid files
Signed-off-by: Balaji Vijayakumar <[email protected]>
1 parent 0126d68 commit cbc6946

File tree

7 files changed

+17
-13
lines changed

7 files changed

+17
-13
lines changed

cmd/limactl/stop.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begi
104104
}
105105

106106
func stopInstanceForcibly(inst *store.Instance) {
107-
if inst.QemuPID > 0 {
108-
logrus.Infof("Sending SIGKILL to the %s driver process %d", inst.VMType, inst.QemuPID)
109-
if err := osutil.SysKill(inst.QemuPID, osutil.SigKill); err != nil {
107+
if inst.DriverPID > 0 {
108+
logrus.Infof("Sending SIGKILL to the %s driver process %d", inst.VMType, inst.DriverPID)
109+
if err := osutil.SysKill(inst.DriverPID, osutil.SigKill); err != nil {
110110
logrus.Error(err)
111111
}
112112
} else {

docs/internal.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ QEMU:
4848
- `serial.sock`: QEMU serial socket, for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serial.sock`)
4949

5050
VZ:
51+
- `vz.pid`: VZ PID
5152
- `vz-identifier`: Unique machine identifier file for a VM
5253
- `vz-efi`: EFIVariable store file for a VM
5354

pkg/qemu/qemu.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ func Cmdline(cfg Config) (string, []string, error) {
622622

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

627627
return exe, args, nil
628628
}

pkg/qemu/qemu_driver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (l *LimaQemuDriver) killQEMU(_ context.Context, _ time.Duration, qCmd *exec
142142
}
143143
qWaitErr := <-qWaitCh
144144
logrus.WithError(qWaitErr).Info("QEMU has exited, after killing forcibly")
145-
qemuPIDPath := filepath.Join(l.Instance.Dir, filenames.QemuPID)
145+
qemuPIDPath := filepath.Join(l.Instance.Dir, filenames.PIDFile(*l.Yaml.VMType))
146146
_ = os.RemoveAll(qemuPIDPath)
147147
return qWaitErr
148148
}

pkg/store/filenames/filenames.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const (
3333
Kernel = "kernel"
3434
KernelCmdline = "kernel.cmdline"
3535
Initrd = "initrd"
36-
QemuPID = "qemu.pid"
3736
QMPSock = "qmp.sock"
3837
SerialLog = "serial.log"
3938
SerialSock = "serial.sock"
@@ -66,3 +65,7 @@ const (
6665
// ssh appends 16 bytes of random characters when it first creates the socket:
6766
// https://github.com/openssh/openssh-portable/blob/V_8_7_P1/mux.c#L1271-L1285
6867
const LongestSock = SSHSock + ".1234567890123456"
68+
69+
func PIDFile(name string) string {
70+
return name + ".pid"
71+
}

pkg/store/instance.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type Instance struct {
4444
Networks []limayaml.Network `json:"network,omitempty"`
4545
SSHLocalPort int `json:"sshLocalPort,omitempty"`
4646
HostAgentPID int `json:"hostAgentPID,omitempty"`
47-
QemuPID int `json:"qemuPID,omitempty"`
47+
DriverPID int `json:"driverPID,omitempty"`
4848
Errors []error `json:"errors,omitempty"`
4949
}
5050

@@ -121,19 +121,19 @@ func Inspect(instName string) (*Instance, error) {
121121
}
122122
}
123123

124-
inst.QemuPID, err = ReadPIDFile(filepath.Join(instDir, filenames.QemuPID))
124+
inst.DriverPID, err = ReadPIDFile(filepath.Join(instDir, filenames.PIDFile(*y.VMType)))
125125
if err != nil {
126126
inst.Status = StatusBroken
127127
inst.Errors = append(inst.Errors, err)
128128
}
129129

130130
if inst.Status == StatusUnknown {
131-
if inst.HostAgentPID > 0 && inst.QemuPID > 0 {
131+
if inst.HostAgentPID > 0 && inst.DriverPID > 0 {
132132
inst.Status = StatusRunning
133-
} else if inst.HostAgentPID == 0 && inst.QemuPID == 0 {
133+
} else if inst.HostAgentPID == 0 && inst.DriverPID == 0 {
134134
inst.Status = StatusStopped
135-
} else if inst.HostAgentPID > 0 && inst.QemuPID == 0 {
136-
inst.Errors = append(inst.Errors, errors.New("host agent is running but qemu is not"))
135+
} else if inst.HostAgentPID > 0 && inst.DriverPID == 0 {
136+
inst.Errors = append(inst.Errors, errors.New("host agent is running but driver is not"))
137137
inst.Status = StatusBroken
138138
} else {
139139
inst.Errors = append(inst.Errors, fmt.Errorf("%s driver is running but host agent is not", inst.VMType))

pkg/vz/vm_darwin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine
6464
case newState := <-machine.StateChangedNotify():
6565
switch newState {
6666
case vz.VirtualMachineStateRunning:
67-
pidFile := filepath.Join(driver.Instance.Dir, filenames.QemuPID)
67+
pidFile := filepath.Join(driver.Instance.Dir, filenames.PIDFile(*driver.Yaml.VMType))
6868
if _, err := os.Stat(pidFile); !errors.Is(err, os.ErrNotExist) {
6969
logrus.Errorf("pidfile %q already exists", pidFile)
7070
errCh <- err

0 commit comments

Comments
 (0)