Skip to content

Commit

Permalink
send sighub before stopping a collector to give chance for clean shut…
Browse files Browse the repository at this point in the history
…down
  • Loading branch information
Marius Sturm committed Jul 28, 2016
1 parent ddda26e commit 136d668
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"os/exec"
"path/filepath"
"syscall"
"time"

"github.com/kardianos/service"
Expand Down Expand Up @@ -161,7 +162,13 @@ func (r *Runner) Start(s service.Service) error {
func (r *Runner) Stop(s service.Service) error {
log.Infof("[%s] Stopping", r.Name)

// deactivate supervisor
r.Running = false

// give the chance to cleanup resources
r.cmd.Process.Signal(syscall.SIGHUP)
time.Sleep(2 * time.Second)

close(r.exit)
if r.cmd.Process != nil {
r.cmd.Process.Kill()
Expand All @@ -171,7 +178,7 @@ func (r *Runner) Stop(s service.Service) error {

func (r *Runner) Restart(s service.Service) error {
r.Stop(s)
time.Sleep(3 * time.Second)
time.Sleep(2 * time.Second)
r.exit = make(chan struct{})
r.Start(s)

Expand Down

0 comments on commit 136d668

Please sign in to comment.