move interrupt signal to main

This commit is contained in:
rasmus 2022-11-09 20:13:50 +02:00
parent f26438f32a
commit c2e4a9eb69
2 changed files with 7 additions and 4 deletions

View File

@ -1,11 +1,13 @@
package main
import (
"context"
"errors"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"git.k-space.ee/k-space/logmower-shipper/pkg/watcher"
"github.com/prometheus/client_golang/prometheus/promhttp"
@ -24,7 +26,9 @@ func main() {
}
}()
if err := watcher.App.Run(os.Args); err != nil {
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt)
if err := watcher.App.RunContext(ctx, os.Args); err != nil {
log.Fatal(err)
}
}

View File

@ -4,7 +4,6 @@ import (
"fmt"
"log"
"os"
"os/signal"
"path/filepath"
"sync"
@ -25,13 +24,14 @@ var App = &cli.App{
// Usage: "rubykana <input>",
// TODO: #2: yaml
Flags: []cli.Flag{
&cli.BoolFlag{Name: "dry-run", Usage: "Do not write to database"}, // TODO:
&cli.BoolFlag{Name: "simulate", Aliases: []string{"dry-run"}, Usage: "Do not write to database"}, // TODO:
&cli.StringFlag{Name: "log-directory", Usage: "Directory to watch for logs", Value: "/var/log/containers"},
&cli.IntFlag{Name: "max-record-size", Value: 128 * 1024, Usage: "Maximum record size in bytes"}, // TODO:
&cli.BoolFlag{Name: "normalize-log-level", Usage: "Normalize log.level values to Syslog defined keywords"}, // TODO:
// &cli.BoolFlag{Name: "parse-json"}, //TODO:
&cli.StringFlag{Category: "k8s metadata", Name: "pod-namespace", EnvVars: []string{"KUBE_POD_NAMESPACE"}}, // TODO:
&cli.StringFlag{Category: "k8s metadata", Name: "node-name", EnvVars: []string{"KUBE_NODE_NAME"}, Required: true},
//
&cli.StringFlag{Category: "secrets", Name: "mongo-uri", EnvVars: []string{"MONGO_URI"}, Usage: "mongodb://foo:bar@host:27017/database", Required: true},
},
Before: func(ctx *cli.Context) error {
@ -43,7 +43,6 @@ var App = &cli.App{
},
Action: func(ctx *cli.Context) error {
ctx.Context, _ = signal.NotifyContext(ctx.Context, os.Interrupt) // TODO: test
var wg sync.WaitGroup
log.Printf("%s %s starting", ctx.App.Name, ctx.App.Version)