Skip to content
Snippets Groups Projects
Unverified Commit c8c2e7fd authored by Levente Pap's avatar Levente Pap Committed by GitHub
Browse files

Terminate GoShimmer without config file (#395)


* Fix #355 Terminate GoShimmer without config file

 - `skip-config` flag to bypass check and supply values
   from cli

* Remove empty line

* Add some comments

* change termination comment

* lower case beginning of comments

* Don't mount config file into docker container by default

* Integration tests skip config file check

* Add flags for logger config

* Log at debug level for integration tests

* Update hive.go to latest version

* upgrade hive.go

Signed-off-by: default avatarWolfgang Welz <welzwo@gmail.com>

Co-authored-by: default avatarLuca Moser <moser.luca@gmail.com>
Co-authored-by: default avatarjonastheis <mail@jonastheis.de>
Co-authored-by: default avatarWolfgang Welz <welzwo@gmail.com>
parent 6d3b2a2c
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,5 @@ EXPOSE 14626/udp ...@@ -39,7 +39,5 @@ EXPOSE 14626/udp
# Copy the Pre-built binary file from the previous stage # Copy the Pre-built binary file from the previous stage
COPY --from=build /go/bin/goshimmer /run/goshimmer COPY --from=build /go/bin/goshimmer /run/goshimmer
# Copy the default config
COPY config.default.json /config.json
ENTRYPOINT ["/run/goshimmer", "--config-dir=/", "--database.directory=/tmp/mainnetdb"] ENTRYPOINT ["/run/goshimmer", "--config-dir=/", "--database.directory=/tmp/mainnetdb"]
...@@ -11,7 +11,7 @@ require ( ...@@ -11,7 +11,7 @@ require (
github.com/gobuffalo/packr/v2 v2.7.1 github.com/gobuffalo/packr/v2 v2.7.1
github.com/golang/protobuf v1.3.5 github.com/golang/protobuf v1.3.5
github.com/gorilla/websocket v1.4.1 github.com/gorilla/websocket v1.4.1
github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522 github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2
github.com/iotaledger/iota.go v1.0.0-beta.14 github.com/iotaledger/iota.go v1.0.0-beta.14
github.com/labstack/echo v3.3.10+incompatible github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0 github.com/labstack/gommon v0.3.0
......
...@@ -145,8 +145,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T ...@@ -145,8 +145,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522 h1:pd7D0jtsF24UKgNTPxXxuZKzPbFKKoau4r066p6GtAo= github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2 h1:vDcNUncyinum1ly5FJPJfYNPZczeo5OLuEpoDu+mxks=
github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522/go.mod h1:LYUD1U+BxF+OY6zCZ4xp38vzjp/QWbUdCw9iwmxkGnc= github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2/go.mod h1:HgYsLMzyQV+eaiUrxa1c7qvH9Jwi2ncycqtlw+Lczhs=
github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8=
github.com/iotaledger/iota.go v1.0.0-beta.14 h1:Oeb28MfBuJEeXcGrLhTCJFtbsnc8y1u7xidsAmiOD5A= github.com/iotaledger/iota.go v1.0.0-beta.14 h1:Oeb28MfBuJEeXcGrLhTCJFtbsnc8y1u7xidsAmiOD5A=
github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8=
......
package config package config
import ( import (
"fmt"
"os"
"github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
"github.com/iotaledger/hive.go/parameter" "github.com/iotaledger/hive.go/parameter"
flag "github.com/spf13/pflag" flag "github.com/spf13/pflag"
...@@ -19,19 +21,10 @@ var ( ...@@ -19,19 +21,10 @@ var (
// flags // flags
configName = flag.StringP("config", "c", "config", "Filename of the config file without the file extension") configName = flag.StringP("config", "c", "config", "Filename of the config file without the file extension")
configDirPath = flag.StringP("config-dir", "d", ".", "Path to the directory containing the config file") configDirPath = flag.StringP("config-dir", "d", ".", "Path to the directory containing the config file")
skipConfigAvailable = flag.Bool("skip-config", false, "Skip config file availability check")
// Node is viper // Node is viper
Node *viper.Viper Node *viper.Viper
// logger
defaultLoggerConfig = logger.Config{
Level: "info",
DisableCaller: false,
DisableStacktrace: false,
Encoding: "console",
OutputPaths: []string{"goshimmer.log"},
DisableEvents: false,
}
) )
// Init triggers the Init event. // Init triggers the Init event.
...@@ -42,10 +35,17 @@ func Init() { ...@@ -42,10 +35,17 @@ func Init() {
func init() { func init() {
// set the default logger config // set the default logger config
Node = viper.New() Node = viper.New()
Node.SetDefault(logger.ViperKey, defaultLoggerConfig)
Plugin.Events.Init.Attach(events.NewClosure(func(*node.Plugin) { Plugin.Events.Init.Attach(events.NewClosure(func(*node.Plugin) {
if err := fetch(false); err != nil { if err := fetch(false); err != nil {
if !*skipConfigAvailable {
// we wanted a config file but it was not present
// global logger instance is not initialized at this stage...
fmt.Println(err.Error())
fmt.Println("no config file present, terminating GoShimmer. please use the provided config.default.json to create a config.json.")
// daemon is not running yet, so we just exit
os.Exit(1)
}
panic(err) panic(err)
} }
})) }))
...@@ -57,7 +57,7 @@ func init() { ...@@ -57,7 +57,7 @@ func init() {
// and ending with: .json, .toml, .yaml or .yml (in this sequence). // and ending with: .json, .toml, .yaml or .yml (in this sequence).
func fetch(printConfig bool, ignoreSettingsAtPrint ...[]string) error { func fetch(printConfig bool, ignoreSettingsAtPrint ...[]string) error {
flag.Parse() flag.Parse()
err := parameter.LoadConfigFile(Node, *configDirPath, *configName, true, true) err := parameter.LoadConfigFile(Node, *configDirPath, *configName, true, *skipConfigAvailable)
if err != nil { if err != nil {
return err return err
} }
......
package logger
import (
flag "github.com/spf13/pflag"
)
const (
// CfgLoggerLevel defines the logger's level.
CfgLoggerLevel = "logger.level"
// CfgLoggerDisableCaller defines whether to disable caller info.
CfgLoggerDisableCaller = "logger.disableCaller"
// CfgLoggerDisableStacktrace defines whether to disable stack trace info.
CfgLoggerDisableStacktrace = "logger.disableStacktrace"
// CfgLoggerEncoding defines the logger's encoding.
CfgLoggerEncoding = "logger.encoding"
// CfgLoggerOutputPaths defines the logger's output paths.
CfgLoggerOutputPaths = "logger.outputPaths"
// CfgLoggerDisableEvents defines whether to disable logger events.
CfgLoggerDisableEvents = "logger.disableEvents"
)
func initFlags() {
flag.String(CfgLoggerLevel, "info", "log level")
flag.Bool(CfgLoggerDisableCaller, false, "disable caller info in log")
flag.Bool(CfgLoggerDisableStacktrace, false, "disable stack trace in log")
flag.String(CfgLoggerEncoding, "console", "log encoding")
flag.StringSlice(CfgLoggerOutputPaths, []string{"stdout", "goshimmer.log"}, "log output paths")
flag.Bool(CfgLoggerDisableEvents, true, "disable logger events")
}
...@@ -19,6 +19,8 @@ func Init() { ...@@ -19,6 +19,8 @@ func Init() {
} }
func init() { func init() {
initFlags()
Plugin.Events.Init.Attach(events.NewClosure(func(*node.Plugin) { Plugin.Events.Init.Attach(events.NewClosure(func(*node.Plugin) {
if err := logger.InitGlobalLogger(config.Node); err != nil { if err := logger.InitGlobalLogger(config.Node); err != nil {
panic(err) panic(err)
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
"github.com/iotaledger/hive.go/workerpool" "github.com/iotaledger/hive.go/workerpool"
flag "github.com/spf13/pflag"
"gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4"
) )
...@@ -38,8 +39,8 @@ type logMessage struct { ...@@ -38,8 +39,8 @@ type logMessage struct {
} }
const ( const (
// CfgServerAddress defines the config flag of the server address. // CfgLoggerRemotelogServerAddress defines the config flag of the server address.
CfgServerAddress = "logger.remotelog.serverAddress" CfgLoggerRemotelogServerAddress = "logger.remotelog.serverAddress"
// CfgDisableEvents defines the config flag for disabling logger events. // CfgDisableEvents defines the config flag for disabling logger events.
CfgDisableEvents = "logger.disableEvents" CfgDisableEvents = "logger.disableEvents"
// PluginName is the name of the remote log plugin. // PluginName is the name of the remote log plugin.
...@@ -57,6 +58,10 @@ var ( ...@@ -57,6 +58,10 @@ var (
workerPool *workerpool.WorkerPool workerPool *workerpool.WorkerPool
) )
func init() {
flag.String(CfgLoggerRemotelogServerAddress, "remotelog.goshimmer.iota.cafe:5213", "RemoteLog server address")
}
func configure(plugin *node.Plugin) { func configure(plugin *node.Plugin) {
log = logger.NewLogger(PluginName) log = logger.NewLogger(PluginName)
...@@ -65,9 +70,9 @@ func configure(plugin *node.Plugin) { ...@@ -65,9 +70,9 @@ func configure(plugin *node.Plugin) {
return return
} }
c, err := net.Dial("udp", config.Node.GetString(CfgServerAddress)) c, err := net.Dial("udp", config.Node.GetString(CfgLoggerRemotelogServerAddress))
if err != nil { if err != nil {
log.Fatalf("Could not create UDP socket to '%s'. %v", config.Node.GetString(CfgServerAddress), err) log.Fatalf("Could not create UDP socket to '%s'. %v", config.Node.GetString(CfgLoggerRemotelogServerAddress), err)
return return
} }
conn = c conn = c
......
...@@ -59,6 +59,8 @@ func (d *DockerContainer) CreateGoShimmerEntryNode(name string, seed string) err ...@@ -59,6 +59,8 @@ func (d *DockerContainer) CreateGoShimmerEntryNode(name string, seed string) err
Image: "iotaledger/goshimmer", Image: "iotaledger/goshimmer",
ExposedPorts: nil, ExposedPorts: nil,
Cmd: strslice.StrSlice{ Cmd: strslice.StrSlice{
"--skip-config=true",
"--logger.level=debug",
fmt.Sprintf("--node.disablePlugins=%s", disabledPluginsEntryNode), fmt.Sprintf("--node.disablePlugins=%s", disabledPluginsEntryNode),
"--autopeering.entryNodes=", "--autopeering.entryNodes=",
fmt.Sprintf("--autopeering.seed=%s", seed), fmt.Sprintf("--autopeering.seed=%s", seed),
...@@ -77,6 +79,8 @@ func (d *DockerContainer) CreateGoShimmerPeer(name string, seed string, entryNod ...@@ -77,6 +79,8 @@ func (d *DockerContainer) CreateGoShimmerPeer(name string, seed string, entryNod
nat.Port("8080/tcp"): {}, nat.Port("8080/tcp"): {},
}, },
Cmd: strslice.StrSlice{ Cmd: strslice.StrSlice{
"--skip-config=true",
"--logger.level=debug",
fmt.Sprintf("--node.disablePlugins=%s", disabledPluginsPeer), fmt.Sprintf("--node.disablePlugins=%s", disabledPluginsPeer),
fmt.Sprintf("--node.enablePlugins=%s", func() string { fmt.Sprintf("--node.enablePlugins=%s", func() string {
if bootstrap { if bootstrap {
......
...@@ -9,7 +9,7 @@ require ( ...@@ -9,7 +9,7 @@ require (
github.com/docker/go-connections v0.4.0 github.com/docker/go-connections v0.4.0
github.com/docker/go-units v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect
github.com/iotaledger/goshimmer v0.1.3 github.com/iotaledger/goshimmer v0.1.3
github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522 github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/stretchr/testify v1.5.1 github.com/stretchr/testify v1.5.1
) )
......
...@@ -139,8 +139,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= ...@@ -139,8 +139,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522 h1:pd7D0jtsF24UKgNTPxXxuZKzPbFKKoau4r066p6GtAo= github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2 h1:vDcNUncyinum1ly5FJPJfYNPZczeo5OLuEpoDu+mxks=
github.com/iotaledger/hive.go v0.0.0-20200430073924-0e16f8c3a522/go.mod h1:LYUD1U+BxF+OY6zCZ4xp38vzjp/QWbUdCw9iwmxkGnc= github.com/iotaledger/hive.go v0.0.0-20200504205557-790e3a7585f2/go.mod h1:HgYsLMzyQV+eaiUrxa1c7qvH9Jwi2ncycqtlw+Lczhs=
github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8=
github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment