From e1abb399cd011719999f7486f8e1e7d0d88efed4 Mon Sep 17 00:00:00 2001 From: i-norden Date: Wed, 27 Oct 2021 14:06:06 -0500 Subject: [PATCH] env vars for log stuff --- cmd/client.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ cmd/env.go | 9 +++++++ cmd/root.go | 1 - 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 cmd/client.go diff --git a/cmd/client.go b/cmd/client.go new file mode 100644 index 0000000..359f5ac --- /dev/null +++ b/cmd/client.go @@ -0,0 +1,72 @@ +// Copyright © 2019 Vulcanize, Inc +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package cmd + +import ( + "os" + "os/signal" + "sync" + + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +// clientCmd represents the serve command +var clientCmd = &cobra.Command{ + Use: "client", + Short: "Client for queuing range requests", + Long: `Usage + +./eth-statediff-service client --config={path to toml config file}`, + Run: func(cmd *cobra.Command, args []string) { + subCommand = cmd.CalledAs() + logWithCommand = *logrus.WithField("SubCommand", subCommand) + client() + }, +} + +func init() { + rootCmd.AddCommand(clientCmd) +} + +func client() { + logWithCommand.Info("Running eth-statediff-service client command") + + statediffService, err := createStateDiffService() + if err != nil { + logWithCommand.Fatal(err) + } + + // start service and clientrs + logWithCommand.Info("Starting statediff service") + wg := new(sync.WaitGroup) + if err := statediffService.Loop(wg); err != nil { + logWithCommand.Fatalf("unable to start statediff service: %v", err) + } + logWithCommand.Info("Starting RPC clientrs") + if err := startServers(statediffService); err != nil { + logWithCommand.Fatal(err) + } + logWithCommand.Info("RPC clientrs successfully spun up; awaiting requests") + + // clean shutdown + shutdown := make(chan os.Signal) + signal.Notify(shutdown, os.Interrupt) + <-shutdown + logWithCommand.Info("Received interrupt signal, shutting down") + statediffService.Stop() + wg.Wait() +} diff --git a/cmd/env.go b/cmd/env.go index 8c21860..ab1cd1e 100644 --- a/cmd/env.go +++ b/cmd/env.go @@ -33,6 +33,8 @@ const ( TRIE_CACHE_SIZE_MB = "TRIE_CACHE_SIZE_MB" LVLDB_PATH = "LVLDB_PATH" LVLDB_ANCIENT = "LVLDB_ANCIENT" + + STATEDIFF_PRERUN = "STATEDIFF_PRERUN" STATEDIFF_TRIE_WORKERS = "STATEDIFF_TRIE_WORKERS" STATEDIFF_SERVICE_WORKERS = "STATEDIFF_SERVICE_WORKERS" STATEDIFF_WORKER_QUEUE_SIZE = "STATEDIFF_WORKER_QUEUE_SIZE" @@ -49,6 +51,9 @@ const ( PRERUN_ONLY = "PRERUN_ONLY" PRERUN_RANGE_START = "PRERUN_RANGE_START" PRERUN_RANGE_STOP = "PRERUN_RANGE_STOP" + + LOG_LEVEL = "LOG_LEVEL" + LOG_FILE_PATH = "LOG_FILE_PATH" ) // Bind env vars for eth node and DB configuration @@ -87,7 +92,11 @@ func init() { viper.BindEnv("statediff.trieWorkers", STATEDIFF_TRIE_WORKERS) viper.BindEnv("statediff.workerQueueSize", STATEDIFF_WORKER_QUEUE_SIZE) + viper.BindEnv("statediff.prerun", STATEDIFF_PRERUN) viper.BindEnv("prerun.only", PRERUN_ONLY) viper.BindEnv("prerun.start", PRERUN_RANGE_START) viper.BindEnv("prerun.stop", PRERUN_RANGE_STOP) + + viper.BindEnv("log.level", LOG_LEVEL) + viper.BindEnv("log.file", LOG_FILE_PATH) } diff --git a/cmd/root.go b/cmd/root.go index d89c967..0a54421 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -84,7 +84,6 @@ func initFuncs(cmd *cobra.Command, args []string) { } func logLevel() error { - viper.BindEnv("log.level", "LOGRUS_LEVEL") lvl, err := log.ParseLevel(viper.GetString("log.level")) if err != nil { return err