Skip to content

Signal handlingΒ #152

@zheka64

Description

@zheka64

Would like to see signal processing for SIGQUIT and SIGTERM in subsequent versions for proper systemd unit operation. Currently, the systemd unit transitions to a failed state after stopping the service.
Here is a short patch for version 0.21.0:

--- main.go.orig    2023-05-24 16:14:47.781711964 +0300
+++ main.go 2023-05-24 14:09:05.000000000 +0300
@@ -181,6 +181,22 @@
    hup := make(chan os.Signal, 1)
    reloadCh = make(chan chan error)
    signal.Notify(hup, syscall.SIGHUP)
+   term_chan := make(chan os.Signal, 1)
+   signal.Notify(term_chan, syscall.SIGTERM, syscall.SIGQUIT)
+   go func(s <-chan os.Signal) {
+       for {
+           sig := <-s
+           switch sig {
+           case syscall.SIGTERM:
+               level.Info(logger).Log("msg", "Got SIGTERM. Exiting")
+               os.Exit(0)
+           case syscall.SIGQUIT:
+               level.Info(logger).Log("msg", "Got SIGQUIT. Exiting")
+               os.Exit(0)
+           }
+       }
+   }(term_chan)
+
    go func() {
        for {
            select {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions