coredhcp.go.template 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2018-present the CoreDHCP Authors. All rights reserved
  2. // This source code is licensed under the MIT license found in the
  3. // LICENSE file in the root directory of this source tree.
  4. package main
  5. import (
  6. "flag"
  7. "time"
  8. "github.com/coredhcp/coredhcp"
  9. "github.com/coredhcp/coredhcp/config"
  10. "github.com/coredhcp/coredhcp/logger"
  11. {{range $plugin := .}}
  12. _ "{{$plugin}}"
  13. {{end}}
  14. "github.com/sirupsen/logrus"
  15. )
  16. var (
  17. flagLogFile = flag.String("logfile", "", "Name of the log file to append to. Default: stdout/stderr only")
  18. flagLogNoStdout = flag.Bool("nostdout", false, "Disable logging to stdout/stderr")
  19. flagDebug = flag.Bool("debug", false, "Enable debug output")
  20. )
  21. func main() {
  22. flag.Parse()
  23. log := logger.GetLogger("main")
  24. if *flagDebug {
  25. log.Logger.SetLevel(logrus.DebugLevel)
  26. log.Infof("Enabled debug logging")
  27. }
  28. if *flagLogFile != "" {
  29. log.Infof("Logging to file %s", *flagLogFile)
  30. logger.WithFile(log, *flagLogFile)
  31. }
  32. if *flagLogNoStdout {
  33. log.Infof("Disabling logging to stdout/stderr")
  34. logger.WithNoStdOutErr(log)
  35. }
  36. config, err := config.Load()
  37. if err != nil {
  38. log.Fatal(err)
  39. }
  40. server := coredhcp.NewServer(config)
  41. if err := server.Start(); err != nil {
  42. log.Fatal(err)
  43. }
  44. if err := server.Wait(); err != nil {
  45. log.Error(err)
  46. }
  47. time.Sleep(time.Second)
  48. }