From ce7768949a447bcb99acfcf9dcf4a54319649945 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Fri, 4 Oct 2019 14:39:48 +0200 Subject: [PATCH] Make sesswatch period configurable --- cmd/daemon/main.go | 8 ++++---- conf/config.toml | 1 + pkg/cfg/cfg.go | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/daemon/main.go b/cmd/daemon/main.go index 5b9c4ea..7d150af 100644 --- a/cmd/daemon/main.go +++ b/cmd/daemon/main.go @@ -72,7 +72,7 @@ func main() { if err != nil { log.Fatal("Could not create pidfile", err) } - runServer(config.Port, outputPath) + runServer(config, outputPath) err = os.Remove(pidfilePath) if err != nil { log.Println("Could not delete pidfile", err) @@ -122,7 +122,7 @@ func (h *recordHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // fmt.Println("exit_code:", r.ExitCode) } -func runServer(port int, outputPath string) { +func runServer(config cfg.Config, outputPath string) { var recordSubscribers []chan records.Record histfileChan := make(chan records.Record) @@ -132,13 +132,13 @@ func runServer(port int, outputPath string) { sesswatchChan := make(chan records.Record) recordSubscribers = append(recordSubscribers, sesswatchChan) - sesswatch.Go(sesswatchChan, []chan string{sessionsToDrop}, 10) + sesswatch.Go(sesswatchChan, []chan string{sessionsToDrop}, config.SesswatchPeriodSeconds) http.HandleFunc("/status", statusHandler) http.Handle("/record", &recordHandler{subscribers: recordSubscribers}) //http.Handle("/session_init", &sessionInitHandler{OutputPath: outputPath}) //http.Handle("/recall", &recallHandler{OutputPath: outputPath}) - http.ListenAndServe(":"+strconv.Itoa(port), nil) + http.ListenAndServe(":"+strconv.Itoa(config.Port), nil) } func killDaemon(pidfile string) error { diff --git a/conf/config.toml b/conf/config.toml index c015120..6642be0 100644 --- a/conf/config.toml +++ b/conf/config.toml @@ -1 +1,2 @@ port = 2627 +sesswatchPeriodSeconds = 120 diff --git a/pkg/cfg/cfg.go b/pkg/cfg/cfg.go index 8373306..0e5fb61 100644 --- a/pkg/cfg/cfg.go +++ b/pkg/cfg/cfg.go @@ -2,5 +2,6 @@ package cfg // Config struct type Config struct { - Port int + Port int + SesswatchPeriodSeconds uint }