-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix: pass through signals to inner container (#83)"
This reverts commit c07d2c2.
- Loading branch information
Showing
10 changed files
with
41 additions
and
247 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"runtime" | ||
"syscall" | ||
|
||
"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)) | ||
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
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.