mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-09 15:10:26 +03:00
Fixed Windows service life-cycle. (#1153)
This fix fixes two issues: https://github.com/yggdrasil-network/yggdrasil-go/issues/993 & https://github.com/yggdrasil-network/yggdrasil-go/issues/1098
This commit is contained in:
parent
5ea16e63a1
commit
4fbdeb4e3f
@ -54,12 +54,12 @@ func main() {
|
|||||||
loglevel := flag.String("loglevel", "info", "loglevel to enable")
|
loglevel := flag.String("loglevel", "info", "loglevel to enable")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
done := make(chan struct{})
|
||||||
|
defer close(done)
|
||||||
|
|
||||||
// Catch interrupts from the operating system to exit gracefully.
|
// Catch interrupts from the operating system to exit gracefully.
|
||||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
// Capture the service being stopped on Windows.
|
|
||||||
minwinsvc.SetOnExit(cancel)
|
|
||||||
|
|
||||||
// Create a new logger that logs output to stdout.
|
// Create a new logger that logs output to stdout.
|
||||||
var logger *log.Logger
|
var logger *log.Logger
|
||||||
switch *logto {
|
switch *logto {
|
||||||
@ -272,6 +272,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Windows service shutdown
|
||||||
|
minwinsvc.SetOnExit(func() {
|
||||||
|
logger.Infof("Shutting down service ...")
|
||||||
|
cancel()
|
||||||
|
// Wait for all parts to shutdown properly
|
||||||
|
<-done
|
||||||
|
})
|
||||||
|
|
||||||
// Block until we are told to shut down.
|
// Block until we are told to shut down.
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user