-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: revert signal pass through handling (#96)
* Revert "fix: add a 1m timeout to signal shutdown (#92)" This reverts commit 0d37a62. * Revert "fix: pass through signals to inner container (#83)" This reverts commit c07d2c2.
- Loading branch information
Showing
11 changed files
with
44 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"runtime" | ||
"syscall" | ||
|
||
"golang.org/x/xerrors" | ||
|
||
"cdr.dev/slog" | ||
"cdr.dev/slog/sloggers/slogjson" | ||
"github.com/coder/envbox/cli" | ||
) | ||
|
||
func main() { | ||
ch := make(chan func() error, 1) | ||
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT, syscall.SIGWINCH) | ||
go func() { | ||
ctx := context.Background() | ||
log := slog.Make(slogjson.Sink(os.Stderr)) | ||
log.Info(ctx, "waiting for signal") | ||
<-sigs | ||
log.Info(ctx, "got signal") | ||
select { | ||
case fn := <-ch: | ||
log.Info(ctx, "running shutdown function") | ||
err := fn() | ||
if err != nil { | ||
log.Error(ctx, "shutdown function failed", slog.Error(err)) | ||
if xerrors.Is(err, context.DeadlineExceeded) { | ||
os.Exit(cli.ExitCodeShutdownTimeout) | ||
} | ||
os.Exit(1) | ||
} | ||
default: | ||
log.Info(ctx, "no shutdown function") | ||
} | ||
log.Info(ctx, "exiting") | ||
os.Exit(0) | ||
}() | ||
_, err := cli.Root(ch).ExecuteC() | ||
_, err := cli.Root().ExecuteC() | ||
if err != nil { | ||
_, _ = fmt.Fprintln(os.Stderr, err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
// We exit the main thread while keepin all the other procs goin strong. | ||
runtime.Goexit() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.