Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd): add respond(d) daemon #191

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d12e62e
[TASK] add respond(d) daemon - WIP
genofire Jan 24, 2019
bd4699f
Improve fetching data for respondd
genofire Apr 10, 2019
d49b1bb
respondd statistics
genofire Apr 10, 2019
c104fd0
respondd batman support
genofire Apr 10, 2019
7934682
respondd statistics traffic
genofire Apr 11, 2019
fafae4c
respondd nodeinfo software (now compareable to mesh-announce)
genofire Apr 11, 2019
1a38b5b
improve example config
genofire Apr 30, 2019
b6072a3
fix batman interfaces
genofire Apr 30, 2019
95ae82f
load default values from config
genofire May 3, 2019
4796c95
[BUGFIX] not crash if batman not exists
genofire May 3, 2019
be9aec7
fix statistics
genofire May 5, 2019
0645ee6
update dep
genofire May 5, 2019
844be71
fix values by zones
genofire May 13, 2019
c201ad3
fast without batman header
genofire May 14, 2019
10e23b5
babel at neighbours
genofire May 18, 2019
f1e9d7e
babel nodeinfo
genofire May 18, 2019
5d03c74
add dep babelweb2-parser
genofire May 18, 2019
a2ec45e
fix dupplicates addreses on babel
genofire May 18, 2019
eefcc27
remove dirty debug code
genofire May 18, 2019
712a41b
WIP: Babel Version
genofire May 21, 2019
8d36fbf
WIP: Babel Version (based on 'junk' branch)
genofire May 29, 2019
ed53d1b
fix failing
genofire Jun 16, 2019
dd98f65
safe data for continues
genofire Jun 16, 2019
6066963
parse ip address in babel library correct
genofire Jun 16, 2019
0b22130
use my fork of babelweb2
genofire Jun 23, 2019
220e8bf
configurate interfaces for mac, addresses and traffic
genofire Jun 23, 2019
a83e8eb
respondd: extends path in systemd unit to get batctl and fastd on def…
genofire Aug 5, 2019
3559c53
gofmt
genofire Jan 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ _testmain.go
*.prof
webroot
/config.toml
/config-respondd.toml
/vendor
/bin
64 changes: 62 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@
[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/shirou/gopsutil"
revision = "01487156ffd97029bd146658b44e4c0d06388d82"

[[constraint]]
name = "github.com/Vivena/babelweb2"
branch = "junk"
source = "github.com/genofire/babelweb2"
31 changes: 4 additions & 27 deletions cmd/config.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,31 @@
package cmd

import (
"fmt"
"io/ioutil"
"os"

"github.com/naoina/toml"

"github.com/FreifunkBremen/yanic/database"
"github.com/FreifunkBremen/yanic/respond"
"github.com/FreifunkBremen/yanic/runtime"
"github.com/FreifunkBremen/yanic/webserver"
)

// Config represents the whole configuration
type Config struct {
Respondd respond.Config
Webserver webserver.Config
Nodes runtime.NodesConfig
Database database.Config
}

var (
configPath string
collector *respond.Collector
nodes *runtime.Nodes
)

func loadConfig() *Config {
config, err := ReadConfigFile(configPath)
if err != nil {
fmt.Fprintln(os.Stderr, "unable to load config file:", err)
os.Exit(2)
}
return config
}

// ReadConfigFile reads a config model from path of a yml file
func ReadConfigFile(path string) (config *Config, err error) {
config = &Config{}

func ReadConfigFile(path string, config interface{}) error {
file, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
return err
}

err = toml.Unmarshal(file, config)
if err != nil {
return nil, err
return err
}

return
return nil
}
8 changes: 5 additions & 3 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
func TestReadConfig(t *testing.T) {
assert := assert.New(t)

config, err := ReadConfigFile("../config_example.toml")
config := &ServeConfig{}
err := ReadConfigFile("../config_example.toml", config)

assert.NoError(err)
assert.NotNil(config)

Expand Down Expand Up @@ -40,11 +42,11 @@ func TestReadConfig(t *testing.T) {
},
}, meshviewer)

_, err = ReadConfigFile("testdata/config_invalid.toml")
err = ReadConfigFile("testdata/config_invalid.toml", config)
assert.Error(err, "not unmarshalable")
assert.Contains(err.Error(), "invalid TOML syntax")

_, err = ReadConfigFile("testdata/adsa.toml")
err = ReadConfigFile("testdata/adsa.toml", config)
assert.Error(err, "not found able")
assert.Contains(err.Error(), "no such file or directory")
}
5 changes: 4 additions & 1 deletion cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ var importCmd = &cobra.Command{
path := args[0]
site := args[1]
domain := args[2]
config := loadConfig()
config := &ServeConfig{}
if err := ReadConfigFile(configPath, config); err != nil {
log.Panicf("unable to load config file: %s", err)
}

err := allDatabase.Start(config.Database)
if err != nil {
Expand Down
40 changes: 40 additions & 0 deletions cmd/respondd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cmd

import (
"os"
"os/signal"
"syscall"

"github.com/bdlm/log"
"github.com/spf13/cobra"

"github.com/FreifunkBremen/yanic/respond/daemon"
)

// serveCmd represents the serve command
var responddCMD = &cobra.Command{
Use: "respondd",
Short: "Runs a respond daemon",
Example: "yanic respondd --config /etc/respondd.toml",
Run: func(cmd *cobra.Command, args []string) {
daemon := &respondd.Daemon{}
if err := ReadConfigFile(configPath, daemon); err != nil {
log.Panicf("unable to load config file: %s", err)
}

go daemon.Start()

log.Info("respondd daemon started")
// Wait for INT/TERM
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
log.Infof("received %s", sig)

},
}

func init() {
RootCmd.AddCommand(responddCMD)
responddCMD.Flags().StringVarP(&configPath, "config", "c", "config-respondd.toml", "Path to configuration file")
}
20 changes: 15 additions & 5 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,42 @@ import (
"github.com/bdlm/log"
"github.com/spf13/cobra"

"github.com/FreifunkBremen/yanic/database"
allDatabase "github.com/FreifunkBremen/yanic/database/all"
allOutput "github.com/FreifunkBremen/yanic/output/all"
"github.com/FreifunkBremen/yanic/respond"
"github.com/FreifunkBremen/yanic/runtime"
"github.com/FreifunkBremen/yanic/webserver"
)

// ServeConfig represents the whole configuration
type ServeConfig struct {
Respondd respond.Config
Webserver webserver.Config
Nodes runtime.NodesConfig
Database database.Config
}

// serveCmd represents the serve command
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Runs the yanic server",
Example: "yanic serve --config /etc/yanic.toml",
Run: func(cmd *cobra.Command, args []string) {
config := loadConfig()
config := &ServeConfig{}
if err := ReadConfigFile(configPath, config); err != nil {
log.Panicf("unable to load config file: %s", err)
}

err := allDatabase.Start(config.Database)
if err != nil {
if err := allDatabase.Start(config.Database); err != nil {
log.Panicf("could not connect to database: %s", err)
}
defer allDatabase.Close()

nodes = runtime.NewNodes(&config.Nodes)
nodes.Start()

err = allOutput.Start(nodes, config.Nodes)
if err != nil {
if err := allOutput.Start(nodes, config.Nodes); err != nil {
log.Panicf("error on init outputs: %s", err)
}
defer allOutput.Close()
Expand Down
30 changes: 30 additions & 0 deletions config-respondd_example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# how ofter the cache respond of a respondd request is calculated
data_interval = "3m"

batman = ["bat03", "bat04"]
babel = "[::1]:33123"

[[listen]]
address = "ff02::2:1001"
interface = "bat03"
port = 1001

[defaults]
node_id = ""
hostname = ""
site_code = "ffhb"
domain_code = ""
vpn = false
interface_mac = "eth0"
interfaces_traffic = [ "eth0" ]
interfaces_address = [ "br-ffhb", "eth0" ]

[defaults.location]
latitude = 53.112446246
longitude = 8.734087944

# if divergent configuration of defaults are wanted by respond on interface/zones example with bat0
[zones.bat03]
node_id = ""
hostname = ""
#...
12 changes: 12 additions & 0 deletions contrib/init/linux-systemd/respondd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=yanic's respondd

[Service]
Type=simple
ExecStart=/opt/go/bin/yanic respondd --config /etc/respondd.conf
Restart=always
RestartSec=5s
Environment=PATH=/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

[Install]
WantedBy=multi-user.target
6 changes: 3 additions & 3 deletions data/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package data

// ResponseData struct
type ResponseData struct {
Neighbours *Neighbours `json:"neighbours"`
Nodeinfo *Nodeinfo `json:"nodeinfo"`
Statistics *Statistics `json:"statistics"`
Nodeinfo *Nodeinfo `json:"nodeinfo" toml:"nodeinfo"`
Statistics *Statistics `json:"statistics" toml:"statistics"`
Neighbours *Neighbours `json:"neighbours" toml:"neighbours"`
CustomFields map[string]interface{} `json:"-"`
}
Loading