-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dispatcher: initial Go commit and env setup (#2192)
- Loading branch information
Showing
10 changed files
with
160 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2018 ETH Zurich | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package config contains the configuration of the SCION dispatcher. | ||
package config | ||
|
||
import "github.com/scionproto/scion/go/lib/common" | ||
|
||
type Config struct { | ||
// ID of the Dispatcher (required) | ||
ID string | ||
} | ||
|
||
func (cfg Config) Validate() error { | ||
if cfg.ID == "" { | ||
return common.NewBasicError("ID must be set", nil) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2018 ETH Zurich | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package config | ||
|
||
const Sample = ` | ||
[dispatcher] | ||
# ID of the Dispatcher (required) | ||
ID = "disp" | ||
[logging] | ||
[logging.file] | ||
# Location of the logging file. | ||
Path = "/var/log/scion/dispatcher.log" | ||
# File logging level (trace|debug|info|warn|error|crit) (default debug) | ||
Level = "debug" | ||
# Max size of log file in MiB (default 50) | ||
# Size = 50 | ||
# Max age of log file in days (default 7) | ||
# MaxAge = 7 | ||
# How frequently to flush to the log file, in seconds. If 0, all messages | ||
# are immediately flushed. If negative, messages are never flushed | ||
# automatically. (default 5) | ||
FlushInterval = 5 | ||
[logging.console] | ||
# Console logging level (trace|debug|info|warn|error|crit) (default crit) | ||
Level = "crit" | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2018 ETH Zurich | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/BurntSushi/toml" | ||
|
||
"github.com/scionproto/scion/go/godispatcher/internal/config" | ||
"github.com/scionproto/scion/go/lib/env" | ||
"github.com/scionproto/scion/go/lib/log" | ||
) | ||
|
||
type Config struct { | ||
Logging env.Logging | ||
Metrics env.Metrics | ||
Dispatcher config.Config | ||
} | ||
|
||
var ( | ||
cfg Config | ||
) | ||
|
||
func main() { | ||
os.Exit(realMain()) | ||
} | ||
|
||
func realMain() int { | ||
env.AddFlags() | ||
flag.Parse() | ||
if returnCode, ok := env.CheckFlags(config.Sample); !ok { | ||
return returnCode | ||
} | ||
if err := setupBasic(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
return 1 | ||
} | ||
defer env.CleanupLog() | ||
defer env.LogAppStopped("Dispatcher", cfg.Dispatcher.ID) | ||
|
||
fatalC := make(chan error, 1) | ||
cfg.Metrics.StartPrometheus(fatalC) | ||
err := <-fatalC | ||
// Prometheus encountered a fatal error, thus we exit. | ||
log.Crit("Unable to listen and serve", "err", err) | ||
return 1 | ||
} | ||
|
||
func setupBasic() error { | ||
if _, err := toml.DecodeFile(env.ConfigFile(), &cfg); err != nil { | ||
return err | ||
} | ||
if err := env.InitLogging(&cfg.Logging); err != nil { | ||
return err | ||
} | ||
env.LogAppStarted("Dispatcher", cfg.Dispatcher.ID) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters