Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop before removing the daemon #102

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions daemon_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions daemon_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions daemon_linux_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions daemon_linux_systemv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions daemon_linux_upstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions daemon_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down