Skip to content

Commit

Permalink
[supervisor] Refactor supervisor exit to allow defer execution
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf authored and roboquat committed Aug 20, 2021
1 parent 5bd688b commit 34b420b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ const (

// Run serves as main entrypoint to the supervisor
func Run(options ...RunOption) {
defer log.Info("supervisor shut down")
exitCode := 0
defer handleExit(&exitCode)

opts := runOptions{
Args: os.Args,
Expand Down Expand Up @@ -277,7 +278,6 @@ func Run(options ...RunOption) {

sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
var exitCode int
select {
case <-sigChan:
case shutdownReason := <-shutdown:
Expand All @@ -297,9 +297,6 @@ func Run(options ...RunOption) {
terminateChildProcesses()

wg.Wait()

log.WithField("exitCode", exitCode).Debug("supervisor exit")
os.Exit(exitCode)
}

func createGitpodService(cfg *Config, tknsrv api.TokenServiceServer) *gitpod.APIoverJSONRPC {
Expand Down Expand Up @@ -1239,3 +1236,9 @@ func runAsGitpodUser(cmd *exec.Cmd) *exec.Cmd {
cmd.SysProcAttr.Credential.Gid = gitpodGID
return cmd
}

func handleExit(ec *int) {
exitCode := *ec
log.WithField("exitCode", exitCode).Debug("supervisor exit")
os.Exit(exitCode)
}

0 comments on commit 34b420b

Please sign in to comment.