feat: improve daemon check by logging existing PIDs to prevent duplicate instances
This commit is contained in:
parent
72705afc16
commit
b2d9167b95
@ -28,13 +28,17 @@ func NewWatchCmd(history *models.History) *cobra.Command {
|
||||
if err == nil {
|
||||
pids := strings.Fields(string(out))
|
||||
myPid := os.Getpid()
|
||||
otherPids := []string{}
|
||||
for _, pidStr := range pids {
|
||||
pid, err := strconv.Atoi(pidStr)
|
||||
if err == nil && pid != myPid {
|
||||
log.Warn().Msg("kcm daemon is already running. Exiting to avoid duplicate daemons.")
|
||||
os.Exit(1)
|
||||
otherPids = append(otherPids, pidStr)
|
||||
}
|
||||
}
|
||||
if len(otherPids) > 0 {
|
||||
log.Warn().Strs("pids", otherPids).Msg("kcm daemon is already running. Exiting to avoid duplicate daemons.")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Set log file path since we are daemonizing
|
||||
|
Loading…
x
Reference in New Issue
Block a user