version command; log resync and super node configs; fix logfile cli flag
This commit is contained in:
parent
5cc3871f45
commit
79c3078c36
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/super_node/resync"
|
"github.com/vulcanize/vulcanizedb/pkg/super_node/resync"
|
||||||
|
v "github.com/vulcanize/vulcanizedb/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// resyncCmd represents the resync command
|
// resyncCmd represents the resync command
|
||||||
@ -41,6 +42,8 @@ func rsyncCmdCommand() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
logWithCommand.Infof("vdb version: %s", v.VersionWithMeta)
|
||||||
|
logWithCommand.Infof("resync config: %+v", rConfig)
|
||||||
if err := ipfs.InitIPFSPlugins(); err != nil {
|
if err := ipfs.InitIPFSPlugins(); err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
38
cmd/root.go
38
cmd/root.go
@ -19,6 +19,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -69,11 +70,23 @@ func Execute() {
|
|||||||
|
|
||||||
func initFuncs(cmd *cobra.Command, args []string) {
|
func initFuncs(cmd *cobra.Command, args []string) {
|
||||||
setViperConfigs()
|
setViperConfigs()
|
||||||
logLvlErr := logLevel()
|
logfile := viper.GetString("logfile")
|
||||||
if logLvlErr != nil {
|
if logfile != "" {
|
||||||
log.Fatal("Could not set log level: ", logLvlErr)
|
file, err := os.OpenFile(logfile,
|
||||||
|
os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||||
|
if err == nil {
|
||||||
|
log.Infof("Directing output to %s", logfile)
|
||||||
|
log.SetOutput(file)
|
||||||
|
} else {
|
||||||
|
log.SetOutput(os.Stdout)
|
||||||
|
log.Info("Failed to log to file, using default stdout")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.SetOutput(os.Stdout)
|
||||||
|
}
|
||||||
|
if err := logLevel(); err != nil {
|
||||||
|
log.Fatal("Could not set log level: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setViperConfigs() {
|
func setViperConfigs() {
|
||||||
@ -140,18 +153,13 @@ func init() {
|
|||||||
func initConfig() {
|
func initConfig() {
|
||||||
if cfgFile != "" {
|
if cfgFile != "" {
|
||||||
viper.SetConfigFile(cfgFile)
|
viper.SetConfigFile(cfgFile)
|
||||||
|
if err := viper.ReadInConfig(); err == nil {
|
||||||
|
log.Printf("Using config file: %s", viper.ConfigFileUsed())
|
||||||
|
} else {
|
||||||
|
log.Fatal(fmt.Sprintf("Couldn't read config file: %s", err.Error()))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
noConfigError := "No config file passed with --config flag"
|
log.Warn("No config file passed with --config flag")
|
||||||
fmt.Println("Error: ", noConfigError)
|
|
||||||
log.Fatal(noConfigError)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := viper.ReadInConfig(); err == nil {
|
|
||||||
log.Printf("Using config file: %s\n\n", viper.ConfigFileUsed())
|
|
||||||
} else {
|
|
||||||
invalidConfigError := "Couldn't read config file"
|
|
||||||
formattedError := fmt.Sprintf("%s: %s", invalidConfigError, err.Error())
|
|
||||||
log.Fatal(formattedError)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
"github.com/vulcanize/vulcanizedb/pkg/ipfs"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/super_node"
|
"github.com/vulcanize/vulcanizedb/pkg/super_node"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
|
||||||
|
v "github.com/vulcanize/vulcanizedb/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// superNodeCmd represents the superNode command
|
// superNodeCmd represents the superNode command
|
||||||
@ -56,6 +57,8 @@ func superNode() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
logWithCommand.Infof("vdb version: %s", v.VersionWithMeta)
|
||||||
|
logWithCommand.Infof("super node config: %+v", superNodeConfig)
|
||||||
if err := ipfs.InitIPFSPlugins(); err != nil {
|
if err := ipfs.InitIPFSPlugins(); err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
41
cmd/version.go
Normal file
41
cmd/version.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright © 2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
v "github.com/vulcanize/vulcanizedb/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// versionCmd represents the version command
|
||||||
|
var versionCmd = &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "Prints the version of vulcanizeDB",
|
||||||
|
Long: `Use this command to fetch the version of vulcanizeDB
|
||||||
|
|
||||||
|
Usage: ./vulcanizedb version`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
subCommand = cmd.CalledAs()
|
||||||
|
logWithCommand = *log.WithField("SubCommand", subCommand)
|
||||||
|
logWithCommand.Infof("VulcanizeDB version: %s", v.VersionWithMeta)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
}
|
17
main.go
17
main.go
@ -1,10 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/cmd"
|
"github.com/vulcanize/vulcanizedb/cmd"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -14,18 +10,5 @@ func main() {
|
|||||||
logrus.SetFormatter(&logrus.TextFormatter{
|
logrus.SetFormatter(&logrus.TextFormatter{
|
||||||
FullTimestamp: true,
|
FullTimestamp: true,
|
||||||
})
|
})
|
||||||
logfile := viper.GetString("logfile")
|
|
||||||
if logfile != "" {
|
|
||||||
file, err := os.OpenFile(logfile,
|
|
||||||
os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
|
||||||
if err == nil {
|
|
||||||
logrus.SetOutput(file)
|
|
||||||
} else {
|
|
||||||
logrus.SetOutput(os.Stdout)
|
|
||||||
logrus.Info("Failed to log to file, using default stdout")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logrus.SetOutput(os.Stdout)
|
|
||||||
}
|
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/super_node/btc"
|
"github.com/vulcanize/vulcanizedb/pkg/super_node/btc"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/super_node/eth"
|
"github.com/vulcanize/vulcanizedb/pkg/super_node/eth"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
|
||||||
|
v "github.com/vulcanize/vulcanizedb/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// APIName is the namespace used for the state diffing service API
|
// APIName is the namespace used for the state diffing service API
|
||||||
@ -141,5 +142,5 @@ func (iapi *InfoAPI) NodeInfo() *p2p.NodeInfo {
|
|||||||
|
|
||||||
// Version returns the version of the super node
|
// Version returns the version of the super node
|
||||||
func (iapi *InfoAPI) Version() string {
|
func (iapi *InfoAPI) Version() string {
|
||||||
return VersionWithMeta
|
return v.VersionWithMeta
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,14 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package super_node
|
package version
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VersionMajor = 0 // Major version component of the current release
|
VersionMajor = 0 // Major version component of the current release
|
||||||
VersionMinor = 1 // Minor version component of the current release
|
VersionMinor = 1 // Minor version component of the current release
|
||||||
VersionPatch = 0 // Patch version component of the current release
|
VersionPatch = 0 // Patch version component of the current release
|
||||||
VersionMeta = "alpha" // Version metadata to append to the version string
|
VersionMeta = "alpha" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,26 +38,3 @@ var VersionWithMeta = func() string {
|
|||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// ArchiveVersion holds the textual version string
|
|
||||||
func ArchiveVersion(gitCommit string) string {
|
|
||||||
vsn := Version
|
|
||||||
if VersionMeta != "stable" {
|
|
||||||
vsn += "-" + VersionMeta
|
|
||||||
}
|
|
||||||
if len(gitCommit) >= 8 {
|
|
||||||
vsn += "-" + gitCommit[:8]
|
|
||||||
}
|
|
||||||
return vsn
|
|
||||||
}
|
|
||||||
|
|
||||||
func VersionWithCommit(gitCommit, gitDate string) string {
|
|
||||||
vsn := VersionWithMeta
|
|
||||||
if len(gitCommit) >= 8 {
|
|
||||||
vsn += "-" + gitCommit[:8]
|
|
||||||
}
|
|
||||||
if (VersionMeta != "stable") && (gitDate != "") {
|
|
||||||
vsn += "-" + gitDate
|
|
||||||
}
|
|
||||||
return vsn
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user