File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import (
20
20
21
21
"github.com/lima-vm/lima/v2/pkg/hostagent"
22
22
"github.com/lima-vm/lima/v2/pkg/hostagent/api/server"
23
+ "github.com/lima-vm/lima/v2/pkg/store"
23
24
)
24
25
25
26
func newHostagentCommand () * cobra.Command {
@@ -46,8 +47,10 @@ func hostagentAction(cmd *cobra.Command, args []string) error {
46
47
return err
47
48
}
48
49
if pidfile != "" {
49
- if _ , err := os .Stat (pidfile ); ! errors .Is (err , os .ErrNotExist ) {
50
- return fmt .Errorf ("pidfile %q already exists" , pidfile )
50
+ if existingPID , err := store .ReadPIDFile (pidfile ); existingPID != 0 {
51
+ return fmt .Errorf ("another hostagent may already be running with pid %d (pidfile %q)" , existingPID , pidfile )
52
+ } else if err != nil {
53
+ return fmt .Errorf ("failed to determine if another hostagent is running: %w" , err )
51
54
}
52
55
if err := os .WriteFile (pidfile , []byte (strconv .Itoa (os .Getpid ())+ "\n " ), 0o644 ); err != nil {
53
56
return err
You can’t perform that action at this time.
0 commit comments