handleSignals function creates and listens on OS signals channel. OS-specific signals that correspond to the program termination (SIGTERM, SIGHUP, SIGINT) will cause this function to return. SIGUSR1 will call reinitLogging without returning.
()
| 37 | // |
| 38 | // SIGUSR1 will call reinitLogging without returning. |
| 39 | func handleSignals() (reload bool) { |
| 40 | sig := make(chan os.Signal, 5) |
| 41 | signal.Notify(sig, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT, syscall.SIGUSR1, syscall.SIGUSR2) |
| 42 | defer signal.Stop(sig) |
| 43 | |
| 44 | for { |
| 45 | switch s := <-sig; s { |
| 46 | case syscall.SIGUSR1: |
| 47 | log.Printf("signal received (%s), rotating logs", s.String()) |
| 48 | systemdStatus(SDReloading, "Reopening logs...") |
| 49 | hooks.RunHooks(hooks.EventLogRotate) |
| 50 | systemdStatus(SDReady, "Listening for incoming connections...") |
| 51 | case syscall.SIGUSR2: |
| 52 | log.Printf("signal received (%s), reloading configuration", s.String()) |
| 53 | return true |
| 54 | default: |
| 55 | go func() { |
| 56 | s := handleSignals() |
| 57 | log.Printf("forced shutdown due to signal (%v)!", s) |
| 58 | os.Exit(1) |
| 59 | }() |
| 60 | |
| 61 | log.Printf("signal received (%v), next signal will force immediate shutdown.", s) |
| 62 | return false |
| 63 | } |
| 64 | } |
| 65 | } |
no test coverage detected