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

Clear/correct logging at program exit #657

Merged
merged 1 commit into from
Jan 17, 2024
Merged
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
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
Loading