Skip to content

Commit

Permalink
Ignore the SIGHUP signal
Browse files Browse the repository at this point in the history
  • Loading branch information
momingkotoba committed Feb 6, 2023
1 parent e34be13 commit 2b7874d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cmd/kafka_gen_log/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (g *LogGenerator) Stat() (l, s int64) {
return
}

//reset logfiles
// reset logfiles
func (g *LogGenerator) Init() error {
g.logfiles = nil
g.off = -1
Expand Down Expand Up @@ -186,7 +186,7 @@ func (g *LogGenerator) Init() error {
return nil
}

//switch to next log file
// switch to next log file
func (g *LogGenerator) next() (err error) {
g.scanner = nil
if g.reader != nil {
Expand Down Expand Up @@ -329,7 +329,7 @@ log_file_pattern: file name pattern, for example, '^secure.*$'`, os.Args[0], os.
util.Logger.Fatal("got error", zap.Error(err))
}

ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
g := &LogGenerator{}
if err := g.Init(); err != nil {
util.Logger.Fatal("got error", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion cmd/kafka_gen_metric/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ topic: for example, sensor_dt_result_online`, os.Args[0], os.Args[0])
}

var prevLines, prevSize int64
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
go generate()

ticker := time.NewTicker(10 * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kafka_gen_prom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ topic: for example, prom_extend`, os.Args[0], os.Args[0])
}

var prevLines, prevSize int64
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
go generate()

ticker := time.NewTicker(10 * time.Second)
Expand Down
7 changes: 5 additions & 2 deletions util/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.
package util

import (
"fmt"

"go.uber.org/zap"
)

Expand All @@ -31,8 +33,9 @@ func Run(appName string, initFunc, jobFunc, cleanupFunc func() error) {
}
}()

WaitForExitSign()
Logger.Info(appName + " got the exit signal, start to clean")
s := WaitForExitSign()
Logger.Info(fmt.Sprintf("%s got the exit signal %s, start to clean", appName, s))

if err := cleanupFunc(); err != nil {
Logger.Fatal(appName+" clean failed", zap.Error(err))
}
Expand Down
6 changes: 3 additions & 3 deletions util/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"syscall"
)

func WaitForExitSign() {
func WaitForExitSign() os.Signal {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
<-c
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
return <-c
}

0 comments on commit 2b7874d

Please sign in to comment.