diff --git a/daemon_darwin.go b/daemon_darwin.go index 0c99343..44ebfb0 100644 --- a/daemon_darwin.go +++ b/daemon_darwin.go @@ -133,6 +133,12 @@ func (darwin *darwinRecord) Remove() (string, error) { return removeAction + failed, ErrNotInstalled } + if _, ok := darwin.checkRunning(); ok { + if err := exec.Command("launchctl", "unload", darwin.servicePath()).Run(); err != nil { + return removeAction + failed, err + } + } + if err := os.Remove(darwin.servicePath()); err != nil { return removeAction + failed, err } diff --git a/daemon_freebsd.go b/daemon_freebsd.go index 2d84d5f..1f83e29 100644 --- a/daemon_freebsd.go +++ b/daemon_freebsd.go @@ -162,6 +162,11 @@ func (bsd *bsdRecord) Remove() (string, error) { if !bsd.isInstalled() { return removeAction + failed, ErrNotInstalled } + if _, ok := bsd.checkRunning(); ok { + if err := exec.Command("service", bsd.name, bsd.getCmd("stop")).Run(); err != nil { + return removeAction + failed, err + } + } if err := os.Remove(bsd.servicePath()); err != nil { return removeAction + failed, err diff --git a/daemon_linux_systemd.go b/daemon_linux_systemd.go index 0fac723..2f1fd9d 100644 --- a/daemon_linux_systemd.go +++ b/daemon_linux_systemd.go @@ -137,6 +137,12 @@ func (linux *systemDRecord) Remove() (string, error) { return removeAction + failed, ErrNotInstalled } + if _, ok := linux.checkRunning(); ok { + if err := exec.Command("systemctl", "stop", linux.name+".service").Run(); err != nil { + return removeAction + failed, err + } + } + if err := linux.systemctl("disable", linux.name+".service").Run(); err != nil { return removeAction + failed, err } diff --git a/daemon_linux_systemv.go b/daemon_linux_systemv.go index 588f6db..bbc9554 100644 --- a/daemon_linux_systemv.go +++ b/daemon_linux_systemv.go @@ -121,6 +121,12 @@ func (linux *systemVRecord) Remove() (string, error) { return removeAction + failed, ErrNotInstalled } + if _, ok := linux.checkRunning(); ok { + if err := exec.Command("service", linux.name, "stop").Run(); err != nil { + return removeAction + failed, err + } + } + if err := os.Remove(linux.servicePath()); err != nil { return removeAction + failed, err } diff --git a/daemon_linux_upstart.go b/daemon_linux_upstart.go index 16216c7..be793a4 100644 --- a/daemon_linux_upstart.go +++ b/daemon_linux_upstart.go @@ -110,6 +110,12 @@ func (linux *upstartRecord) Remove() (string, error) { return removeAction + failed, ErrNotInstalled } + if _, ok := linux.checkRunning(); ok { + if err := exec.Command("stop", linux.name).Run(); err != nil { + return removeAction + failed, err + } + } + if err := os.Remove(linux.servicePath()); err != nil { return removeAction + failed, err } diff --git a/daemon_windows.go b/daemon_windows.go index 047b635..fc38382 100644 --- a/daemon_windows.go +++ b/daemon_windows.go @@ -107,6 +107,9 @@ func (windows *windowsRecord) Remove() (string, error) { return removeAction + failed, getWindowsError(err) } defer s.Close() + if err := stopAndWait(s); err != nil { + return removeAction + failed, getWindowsError(err) + } err = s.Delete() if err != nil { return removeAction + failed, getWindowsError(err)