| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- // Copyright 2018-present the CoreDHCP Authors. All rights reserved
- // This source code is licensed under the MIT license found in the
- // LICENSE file in the root directory of this source tree.
- package main
- import (
- "flag"
- "time"
- "github.com/coredhcp/coredhcp"
- "github.com/coredhcp/coredhcp/config"
- "github.com/coredhcp/coredhcp/logger"
- "github.com/coredhcp/coredhcp/plugins"
- {{range $plugin := .}}
- {{if eq $plugin "github.com/coredhcp/coredhcp/plugins/range"}}rangepl "{{$plugin}}"{{else}}"{{$plugin}}"{{end}}
- {{end}}
- "github.com/sirupsen/logrus"
- )
- var (
- flagLogFile = flag.String("logfile", "", "Name of the log file to append to. Default: stdout/stderr only")
- flagLogNoStdout = flag.Bool("nostdout", false, "Disable logging to stdout/stderr")
- flagDebug = flag.Bool("debug", false, "Enable debug output")
- )
- var desiredPlugins = []*plugins.Plugin{
- {{range $plugin := .}}
- {{$import := importname $plugin}}&{{if eq $import "range"}}rangepl{{else}}{{$import}}{{end}}.Plugin,
- {{end}}
- }
- func main() {
- flag.Parse()
- log := logger.GetLogger("main")
- if *flagDebug {
- log.Logger.SetLevel(logrus.DebugLevel)
- log.Infof("Enabled debug logging")
- }
- if *flagLogFile != "" {
- log.Infof("Logging to file %s", *flagLogFile)
- logger.WithFile(log, *flagLogFile)
- }
- if *flagLogNoStdout {
- log.Infof("Disabling logging to stdout/stderr")
- logger.WithNoStdOutErr(log)
- }
- config, err := config.Load()
- if err != nil {
- log.Fatal(err)
- }
- // register plugins
- for _, plugin := range desiredPlugins {
- if err := plugins.RegisterPlugin(plugin); err != nil {
- log.Fatalf("Failed to register plugin '%s': %v", plugin.Name, err)
- }
- }
- // start server
- server := coredhcp.NewServer(config)
- if err := server.Start(); err != nil {
- log.Fatal(err)
- }
- if err := server.Wait(); err != nil {
- log.Error(err)
- }
- time.Sleep(time.Second)
- }
|