Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 10, 2024
1 parent 4f4683b commit b29665f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 7 additions & 2 deletions local/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"time"

"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/symfony-cli/console"
"github.com/symfony-cli/symfony-cli/inotify"
"github.com/symfony-cli/symfony-cli/local/pid"
Expand Down Expand Up @@ -80,7 +81,12 @@ func NewRunner(pidFile *pid.PidFile, mode runnerMode) (*Runner, error) {
}

func (r *Runner) Run() error {
logger := terminal.Logger.With().Str("cmd", r.pidFile.String()).Logger()
lw, err := r.pidFile.LogWriter()
if err != nil {
return err
}
logger := zerolog.New(lw).With().Str("source", "runner").Str("cmd", r.pidFile.String()).Timestamp().Logger()

if r.mode == RunnerModeLoopDetached {
if !reexec.IsChild() {
varDir := filepath.Join(util.GetHomeDir(), "var")
Expand Down Expand Up @@ -179,7 +185,6 @@ func (r *Runner) Run() error {
if r.mode == RunnerModeLoopDetached {
reexec.NotifyForeground("started")
}

logger.Debug().Msg("Waiting for channels (first boot)")
select {
case err := <-cmdExitChan:
Expand Down
9 changes: 6 additions & 3 deletions reexec/reexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func ExecBinaryWithEnv(binary string, envs []string) bool {
}

func Background(homeDir string) error {
terminal.Logger.Debug().Str("source", "reexec").Msg("let's go to the background!")
if util.IsGoRun() {
return errors.New("Not applicable in a Go run context")
}
Expand Down Expand Up @@ -116,7 +117,6 @@ func Background(homeDir string) error {
os.Setenv("REEXEC_WATCH_PID", shellPID)
}

terminal.Logger.Debug().Msg("Let's go to the background!")
p, err := Respawn()
if err != nil {
return errors.Wrap(err, "Could not respawn")
Expand Down Expand Up @@ -157,14 +157,13 @@ func Background(homeDir string) error {
// end-up receiving a status in statusCh so no particular
// processing to do here.
case event := <-watcherChan:
terminal.Logger.Info().Msg("FS event received: " + event.Event().String())
terminal.Logger.Debug().Str("source", "reexec").Msg("FS event received: " + event.Event().String())
if event.Event() == notify.Remove {
return nil
}

if event.Event() == notify.Write {
ticker.Stop()
break
}
case status := <-statusCh:
return console.Exit("", status)
Expand All @@ -176,6 +175,7 @@ func Background(homeDir string) error {
}

func NotifyForeground(status string) error {
terminal.Logger.Debug().Str("source", "reexec").Msg("notify foreground")
if !IsChild() {
return nil
}
Expand All @@ -195,6 +195,7 @@ func NotifyForeground(status string) error {
}

func WatchParent(stopCh chan bool) error {
terminal.Logger.Debug().Str("source", "reexec").Msg("watch parent")
spid := os.Getenv("REEXEC_WATCH_PID")
if spid == "" {
return nil
Expand Down Expand Up @@ -223,6 +224,7 @@ func WatchParent(stopCh chan bool) error {
}

func Restart(postRespawn func()) error {
terminal.Logger.Debug().Str("source", "reexec").Msg("restart")
if err := os.Setenv("REEXEC_PPID", fmt.Sprint(os.Getpid())); nil != err {
return errors.WithStack(err)
}
Expand Down Expand Up @@ -280,6 +282,7 @@ func Restart(postRespawn func()) error {
}

func Respawn() (*os.Process, error) {
terminal.Logger.Debug().Str("source", "reexec").Msg("respawn")
argv0, err := console.CurrentBinaryPath()
if err != nil {
return nil, err
Expand Down

0 comments on commit b29665f

Please sign in to comment.