github.com/wangyougui/gf/v2@v2.6.5/net/ghttp/ghttp_server_admin_unix.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  //go:build !windows
     8  // +build !windows
     9  
    10  package ghttp
    11  
    12  import (
    13  	"context"
    14  	"os"
    15  	"syscall"
    16  
    17  	"github.com/wangyougui/gf/v2/internal/intlog"
    18  	"github.com/wangyougui/gf/v2/os/glog"
    19  	"github.com/wangyougui/gf/v2/os/gproc"
    20  )
    21  
    22  // handleProcessSignal handles all signals from system in blocking way.
    23  func handleProcessSignal() {
    24  	var ctx = context.TODO()
    25  	gproc.AddSigHandlerShutdown(func(sig os.Signal) {
    26  		shutdownWebServersGracefully(ctx, sig)
    27  	})
    28  	gproc.AddSigHandler(func(sig os.Signal) {
    29  		// If the graceful restart feature is not enabled,
    30  		// it does nothing except printing a warning log.
    31  		if !gracefulEnabled {
    32  			glog.Warning(ctx, "graceful reload feature is disabled")
    33  			return
    34  		}
    35  		if err := restartWebServers(ctx, sig, ""); err != nil {
    36  			intlog.Errorf(ctx, `%+v`, err)
    37  		}
    38  	}, syscall.SIGUSR1)
    39  
    40  	gproc.Listen()
    41  }