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 (
2020
2121 "github.com/lima-vm/lima/v2/pkg/hostagent"
2222 "github.com/lima-vm/lima/v2/pkg/hostagent/api/server"
23+ "github.com/lima-vm/lima/v2/pkg/store"
2324)
2425
2526func newHostagentCommand () * cobra.Command {
@@ -46,8 +47,10 @@ func hostagentAction(cmd *cobra.Command, args []string) error {
4647 return err
4748 }
4849 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 )
5154 }
5255 if err := os .WriteFile (pidfile , []byte (strconv .Itoa (os .Getpid ())+ "\n " ), 0o644 ); err != nil {
5356 return err
You can’t perform that action at this time.
0 commit comments