returning nil for windows pid

This commit is contained in:
afeiszli 2022-07-27 17:44:14 -04:00
parent 884d1938e6
commit 1a49db79ab
2 changed files with 14 additions and 15 deletions

View file

@ -36,20 +36,19 @@ func Restart() error {
if ncutils.IsWindows() {
RestartWindowsDaemon()
return nil
} else {
pid, err := ncutils.ReadPID()
if err != nil {
return fmt.Errorf("failed to find pid %w", err)
}
p, err := os.FindProcess(pid)
if err != nil {
return fmt.Errorf("failed to find running process for pid %d -- %w", pid, err)
}
if err := p.Signal(syscall.SIGHUP); err != nil {
return fmt.Errorf("SIGHUP failed -- %w", err)
}
return nil
}
pid, err := ncutils.ReadPID()
if err != nil {
return fmt.Errorf("failed to find pid %w", err)
}
p, err := os.FindProcess(pid)
if err != nil {
return fmt.Errorf("failed to find running process for pid %d -- %w", pid, err)
}
if err := p.Signal(syscall.SIGHUP); err != nil {
return fmt.Errorf("SIGHUP failed -- %w", err)
}
return nil
}
// Start - starts system daemon

View file

@ -20,7 +20,7 @@ func (*WindowsPIDError) Error() string {
// SavePID - saves the pid of running program to disk
func SavePID() error {
if IsWindows() {
return &WindowsPIDError{}
return nil
}
pid := os.Getpid()
if err := os.WriteFile(PIDFILE, []byte(fmt.Sprintf("%d", pid)), 0644); err != nil {
@ -32,7 +32,7 @@ func SavePID() error {
// ReadPID - reads a previously saved pid from disk
func ReadPID() (int, error) {
if IsWindows() {
return 0, &WindowsPIDError{}
return 0, nil
}
bytes, err := os.ReadFile(PIDFILE)
if err != nil {