| 22 | var pidFile string |
| 23 | |
| 24 | func initDaemon() { |
| 25 | ex, err := os.Executable() |
| 26 | if err != nil { |
| 27 | log.Fatal(err) |
| 28 | } |
| 29 | exPath := filepath.Dir(ex) |
| 30 | _ = os.MkdirAll(filepath.Join(exPath, "daemon"), 0700) |
| 31 | pidFile = filepath.Join(exPath, "daemon/pid") |
| 32 | if utils.Exists(pidFile) { |
| 33 | bytes, err := os.ReadFile(pidFile) |
| 34 | if err != nil { |
| 35 | log.Fatal("failed to read pid file", err) |
| 36 | } |
| 37 | id, err := strconv.Atoi(string(bytes)) |
| 38 | if err != nil { |
| 39 | log.Fatal("failed to parse pid data", err) |
| 40 | } |
| 41 | pid = id |
| 42 | } |
| 43 | } |