Skip to content

Commit

Permalink
Merge pull request #657 from haoming29/better-exit-log
Browse files Browse the repository at this point in the history
Clear/correct logging at program exit
  • Loading branch information
haoming29 authored Jan 17, 2024
2 parents 39ea7aa + de0f4fb commit 2e369ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func Execute() error {
defer func() {
err := egrp.Wait()
if err != nil {
if err.Error() == "Federation process has been cancelled" {
log.Info("Process was shutdown")
return
}
log.Errorln("Error occurred when shutting down process:", err)
}
}()
Expand Down
5 changes: 4 additions & 1 deletion daemon/launch_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type (
ctx context.Context
expiry time.Time
pid int
name string
}
)

Expand Down Expand Up @@ -105,7 +106,7 @@ func (launcher DaemonLauncher) Launch(ctx context.Context) (context.Context, int
if launcher.Uid != -1 && launcher.Gid != -1 {
cmd.SysProcAttr = &syscall.SysProcAttr{}
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(launcher.Uid), Gid: uint32(launcher.Gid)}
log.Infof("Will launch daemon with UID %v and GID %v", launcher.Uid, launcher.Gid)
log.Infof("Will launch daemon %q with UID %v and GID %v", launcher.DaemonName, launcher.Uid, launcher.Gid)
} else if launcher.Uid != -1 || launcher.Gid != -1 {
return ctx, -1, errors.New("If either uid or gid is specified for daemon, both must be specified")
}
Expand Down Expand Up @@ -135,6 +136,7 @@ func LaunchDaemons(ctx context.Context, launchers []Launcher, egrp *errgroup.Gro
}
daemons[idx].ctx = ctx
daemons[idx].pid = pid
daemons[idx].name = daemon.Name()
log.Infoln("Successfully launched", daemon.Name())
metrics.SetComponentHealthStatus(metrics.HealthStatusComponent(daemon.Name()), metrics.StatusOK, "")
}
Expand Down Expand Up @@ -168,6 +170,7 @@ func LaunchDaemons(ctx context.Context, launchers []Launcher, egrp *errgroup.Gro
lastErr = errors.Wrapf(err, "Failed to forward signal to %s process", launchers[idx].Name())
}
daemon.expiry = time.Now().Add(10 * time.Second)
log.Infof("Daemon %q with pid %d was killed", daemon.name, daemon.pid)
}
if lastErr != nil {
log.Errorln("Last error when killing launched daemons:", lastErr)
Expand Down

0 comments on commit 2e369ac

Please sign in to comment.