Skip to content

Commit

Permalink
Replace long sleep by a select{}, add signal handling
Browse files Browse the repository at this point in the history
- `select {}` is the idiomatic way of doing nothing
- Signal handling will avoid waiting 10s after a `docker compose down`
  if you have not set `init: true`
  • Loading branch information
louisroyer committed Sep 21, 2023
1 parent 8f56e02 commit 485ed9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ import (
"fmt"
"log"
"os"
"os/signal"
"syscall"

trunks "github.com/shynuu/trunks/runtime"
"github.com/urfave/cli/v2"
)

// Initialize signals handling
func initSignals() {
cancelChan := make(chan os.Signal, 1)
signal.Notify(cancelChan, syscall.SIGTERM, syscall.SIGINT)
func(_ os.Signal) {}(<-cancelChan)
os.Exit(0)
}

func main() {
var config string
var flush bool = false
Expand Down Expand Up @@ -82,7 +92,7 @@ func main() {
return nil
},
}

go initSignals()
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion runtime/trunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (t *TrunksConfig) Run() {
scheduler.StartBlocking()
} else {
log.Println("Trunks started without ACM")
time.Sleep(time.Duration(1<<63 - 1))
select {}
}

}

0 comments on commit 485ed9e

Please sign in to comment.