Skip to content

Handle better interrupt signals #63

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

Merged
merged 1 commit into from
Mar 21, 2025
Merged
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
29 changes: 16 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ func runIt(recipe internal.Recipe) error {
return fmt.Errorf("failed to create docker runner: %w", err)
}

sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt)

if err := dockerRunner.Run(); err != nil {
dockerRunner.Stop()
return fmt.Errorf("failed to run docker: %w", err)
}

Expand All @@ -138,23 +142,20 @@ func runIt(recipe internal.Recipe) error {
}
}

// wait for service readiness
if err := internal.WaitForReady(svcManager); err != nil {
dockerRunner.Stop()
return fmt.Errorf("failed to wait for service readiness: %w", err)
}

watchdogErr := make(chan error, 1)
if watchdog {
go func() {
readyErr := make(chan error, 1)

go func() {
if err := internal.WaitForReady(svcManager); err != nil {
readyErr <- fmt.Errorf("failed to wait for service readiness: %w", err)
}

if watchdog {
if err := internal.RunWatchdog(svcManager); err != nil {
watchdogErr <- fmt.Errorf("watchdog failed: %w", err)
}
}()
}

sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt)
}
}()

var timerCh <-chan time.Time
if timeout > 0 {
Expand All @@ -166,6 +167,8 @@ func runIt(recipe internal.Recipe) error {
fmt.Println("Stopping...")
case err := <-dockerRunner.ExitErr():
fmt.Println("Service failed:", err)
case err := <-readyErr:
fmt.Println("Service failed to start:", err)
case err := <-watchdogErr:
fmt.Println("Watchdog failed:", err)
case <-timerCh:
Expand Down