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 package main
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"os" "os"
"os/signal"
"git.k-space.ee/k-space/logmower-shipper/pkg/watcher" "git.k-space.ee/k-space/logmower-shipper/pkg/watcher"
"github.com/prometheus/client_golang/prometheus/promhttp" "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) log.Fatal(err)
} }
} }

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"os/signal"
"path/filepath" "path/filepath"
"sync" "sync"
@ -25,13 +24,14 @@ var App = &cli.App{
// Usage: "rubykana <input>", // Usage: "rubykana <input>",
// TODO: #2: yaml // TODO: #2: yaml
Flags: []cli.Flag{ 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.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.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: "normalize-log-level", Usage: "Normalize log.level values to Syslog defined keywords"}, // TODO:
// &cli.BoolFlag{Name: "parse-json"}, //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: "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: "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}, &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 { Before: func(ctx *cli.Context) error {
@ -43,7 +43,6 @@ var App = &cli.App{
}, },
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
ctx.Context, _ = signal.NotifyContext(ctx.Context, os.Interrupt) // TODO: test
var wg sync.WaitGroup var wg sync.WaitGroup
log.Printf("%s %s starting", ctx.App.Name, ctx.App.Version) log.Printf("%s %s starting", ctx.App.Name, ctx.App.Version)