Skip to content

Commit

Permalink
Execute "up.shutdown" when exiting "okteto up" (#953)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chico de Guzman <pchico83@gmail.com>
  • Loading branch information
pchico83 committed Jun 25, 2020
1 parent 12c02b5 commit 141940f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func (up *upContext) start(autoDeploy, build, resetSyncthing bool) error {
analytics.TrackUp(true, up.Dev.Name, up.getClusterType(), len(up.Dev.Services) == 0, up.isSwap, up.Dev.RemoteModeEnabled())

go up.activate(autoDeploy, build, resetSyncthing)
defer up.shutdown()

select {
case <-stop:
Expand Down
6 changes: 4 additions & 2 deletions pkg/syncthing/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"
)

func terminate(pid int) error {
func terminate(pid int, wait bool) error {
proc := os.Process{Pid: pid}
if err := proc.Signal(os.Interrupt); err != nil {
if strings.Contains(err.Error(), "process already finished") {
Expand All @@ -30,7 +30,9 @@ func terminate(pid int) error {
return err
}

defer proc.Wait() // nolint: errcheck
if wait {
defer proc.Wait() // nolint: errcheck
}

return nil
}
2 changes: 1 addition & 1 deletion pkg/syncthing/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ import (
"github.com/mattn/psutil"
)

func terminate(pid int) error {
func terminate(pid int, wait bool) error {
return psutil.TerminateTree(pid, 0)
}
6 changes: 3 additions & 3 deletions pkg/syncthing/syncthing.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func New(dev *model.Dev) (*Syncthing, error) {
return s, nil
}

func (s *Syncthing) cleanupDaemon(pid int) error {
func (s *Syncthing) cleanupDaemon(pid int, wait bool) error {
process, err := ps.FindProcess(pid)
if process == nil && err == nil {
return nil
Expand All @@ -204,7 +204,7 @@ func (s *Syncthing) cleanupDaemon(pid int) error {
return nil
}

err = terminate(pid)
err = terminate(pid, wait)
if err == nil {
log.Infof("terminated syncthing with pid %d", pid)
}
Expand Down Expand Up @@ -590,7 +590,7 @@ func (s *Syncthing) Stop(force bool) error {
}
}

if err := s.cleanupDaemon(pid); err != nil {
if err := s.cleanupDaemon(pid, force); err != nil {
return err
}

Expand Down

0 comments on commit 141940f

Please sign in to comment.