Send MAINPID to systemd when reexecing for logfile output

This allows the new process to notify systemd when it is ready.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
Brad Davidson 2021-09-29 00:24:48 -07:00 committed by Brad Davidson
parent a16105b348
commit 5d1a37ee32

View File

@ -9,6 +9,7 @@ import (
"sync"
"time"
systemd "github.com/coreos/go-systemd/daemon"
"github.com/docker/docker/pkg/reexec"
"github.com/natefinch/lumberjack"
"github.com/rancher/k3s/pkg/version"
@ -98,7 +99,11 @@ func runWithLogging() error {
cmd.Stderr = l
cmd.Stdout = l
cmd.Stdin = os.Stdin
return cmd.Run()
if err := cmd.Start(); err != nil {
return err
}
systemd.SdNotify(false, fmt.Sprintf("MAINPID=%d\n", cmd.Process.Pid))
return cmd.Wait()
}
func setupLogging() {