-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
134 changed files
with
33,290 additions
and
382 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"log" | ||
"log/syslog" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog" | ||
"github.com/skycoin/skycoin/src/util/logging" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/skycoin/skywire/internal/metrics" | ||
"github.com/skycoin/skywire/pkg/setup" | ||
) | ||
|
||
var ( | ||
metricsAddr string | ||
syslogAddr string | ||
tag string | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "setup-node [config.json]", | ||
Short: "Route Setup Node for skywire", | ||
Run: func(_ *cobra.Command, args []string) { | ||
configFile := "config.json" | ||
if len(args) > 0 { | ||
configFile = args[0] | ||
} | ||
conf := parseConfig(configFile) | ||
|
||
logger := logging.MustGetLogger(tag) | ||
if syslogAddr != "" { | ||
hook, err := logrus_syslog.NewSyslogHook("udp", syslogAddr, syslog.LOG_INFO, tag) | ||
if err != nil { | ||
logger.Fatalf("Unable to connect to syslog daemon on %v", syslogAddr) | ||
} | ||
logging.AddHook(hook) | ||
} | ||
|
||
sn, err := setup.NewNode(conf, metrics.NewPrometheus("setupnode")) | ||
if err != nil { | ||
logger.Fatal("Failed to setup Node: ", err) | ||
} | ||
|
||
go func() { | ||
http.Handle("/metrics", promhttp.Handler()) | ||
if err := http.ListenAndServe(metricsAddr, nil); err != nil { | ||
logger.Println("Failed to start metrics API:", err) | ||
} | ||
}() | ||
|
||
logger.Fatal(sn.Serve(context.Background())) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.Flags().StringVarP(&metricsAddr, "metrics", "m", ":2121", "address to bind metrics API to") | ||
rootCmd.Flags().StringVar(&syslogAddr, "syslog", "", "syslog server address. E.g. localhost:514") | ||
rootCmd.Flags().StringVar(&tag, "tag", "setup-node", "logging tag") | ||
} | ||
|
||
func parseConfig(path string) *setup.Config { | ||
file, err := os.Open(path) | ||
if err != nil { | ||
log.Fatalf("Failed to open config: %s", err) | ||
} | ||
|
||
conf := &setup.Config{} | ||
if err := json.NewDecoder(file).Decode(&conf); err != nil { | ||
log.Fatalf("Failed to decode %s: %s", path, err) | ||
} | ||
|
||
return conf | ||
} | ||
|
||
// Execute executes root CLI command. | ||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"public_key": "024ec47420176680816e0406250e7156465e4531f5b26057c9f6297bb0303558c7", | ||
"secret_key": "42bca4df2f3189b28872d40e6c61aacd5e85b8e91f8fea65780af27c142419e5", | ||
"messaging": { | ||
"discovery": "http://skywire.skycoin.net:8001", | ||
"server_count": 1 | ||
}, | ||
"transport_discovery": "http://skywire.skycoin.net:8003", | ||
"log_level": "info" | ||
} |
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,7 @@ | ||
package main | ||
|
||
import "github.com/skycoin/skywire/cmd/setup-node/commands" | ||
|
||
func main() { | ||
commands.Execute() | ||
} |
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
Oops, something went wrong.