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

Catch signals for graceful fleet desktop exit #23054

Open
wants to merge 3 commits into
base: main
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
1 change: 1 addition & 0 deletions changes/21256-fleet-desktop-trap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Gracefully shutdown fleet desktop when receiving interrupt and terminate signals
dantecatalfamo marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 22 additions & 1 deletion orbit/cmd/desktop/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"errors"
"fmt"
"os"
"os/signal"
"path/filepath"
"runtime"
"syscall"
"time"

"fyne.io/systray"
Expand Down Expand Up @@ -438,17 +440,36 @@ func main() {
// FIXME: it doesn't look like this is actually triggering, at least when desktop gets
// killed (https://github.com/fleetdm/fleet/issues/21256)
onExit := func() {
log.Info().Msg("exit")
log.Info().Msg("exiting")
if mdmMigrator != nil {
log.Debug().Err(err).Msg("exiting mdmMigrator")
mdmMigrator.Exit()
}
if swiftDialogCh != nil {
log.Debug().Err(err).Msg("exiting swiftDialogCh")
close(swiftDialogCh)
}
log.Debug().Msg("stopping ticker")
summaryTicker.Stop()
log.Debug().Msg("canceling offline watcher ctx")
cancelOfflineWatcherCtx()
}

sigChan := make(chan os.Signal, 1)
signal.Notify(
sigChan,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT,
)

// Catch signals and exit gracefully
go func() {
s := <-sigChan
log.Info().Stringer("signal", s).Msg("Caught signal, exiting")
systray.Quit()
}()
lucasmrod marked this conversation as resolved.
Show resolved Hide resolved

systray.Run(onReady, onExit)
}

Expand Down
2 changes: 1 addition & 1 deletion orbit/pkg/useraction/mdm_migration_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type baseDialog struct {
}

func newBaseDialog(path string) *baseDialog {
return &baseDialog{path: path, interruptCh: make(chan struct{})}
return &baseDialog{path: path, interruptCh: make(chan struct{}, 1)}
lucasmrod marked this conversation as resolved.
Show resolved Hide resolved
}

func (b *baseDialog) CanRun() bool {
Expand Down
Loading