mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-15 01:54:03 +02:00
refactor: utils.WaitExit
This commit is contained in:
parent
40aa937f54
commit
fd223c7542
2 changed files with 18 additions and 11 deletions
12
cmd/main.go
12
cmd/main.go
|
@ -138,17 +138,7 @@ func main() {
|
||||||
|
|
||||||
config.WatchChanges()
|
config.WatchChanges()
|
||||||
|
|
||||||
sig := make(chan os.Signal, 1)
|
task.WaitExit(cfg.Value().TimeoutShutdown)
|
||||||
signal.Notify(sig, syscall.SIGINT)
|
|
||||||
signal.Notify(sig, syscall.SIGTERM)
|
|
||||||
signal.Notify(sig, syscall.SIGHUP)
|
|
||||||
|
|
||||||
// wait for signal
|
|
||||||
<-sig
|
|
||||||
|
|
||||||
// gracefully shutdown
|
|
||||||
logging.Info().Msg("shutting down")
|
|
||||||
_ = task.GracefulShutdown(time.Second * time.Duration(cfg.Value().TimeoutShutdown))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareDirectory(dir string) {
|
func prepareDirectory(dir string) {
|
||||||
|
|
|
@ -4,6 +4,9 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/internal/logging"
|
"github.com/yusing/go-proxy/internal/logging"
|
||||||
|
@ -73,3 +76,17 @@ func GracefulShutdown(timeout time.Duration) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WaitExit(shutdownTimeout int) {
|
||||||
|
sig := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sig, syscall.SIGINT)
|
||||||
|
signal.Notify(sig, syscall.SIGTERM)
|
||||||
|
signal.Notify(sig, syscall.SIGHUP)
|
||||||
|
|
||||||
|
// wait for signal
|
||||||
|
<-sig
|
||||||
|
|
||||||
|
// gracefully shutdown
|
||||||
|
logging.Info().Msg("shutting down")
|
||||||
|
_ = GracefulShutdown(time.Second * time.Duration(shutdownTimeout))
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue