main.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2015 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "flag"
  17. "fmt"
  18. "os"
  19. "path/filepath"
  20. "github.com/coreos/pkg/capnslog"
  21. )
  22. var plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcd-agent")
  23. func main() {
  24. etcdPath := flag.String("etcd-path", filepath.Join(os.Getenv("GOPATH"), "bin/etcd"), "the path to etcd binary")
  25. etcdLogDir := flag.String("etcd-log-dir", "etcd-log", "directory to store etcd logs, data directories, failure archive")
  26. port := flag.String("port", ":9027", "port to serve agent server")
  27. useRoot := flag.Bool("use-root", true, "use root permissions")
  28. failpointAddr := flag.String("failpoint-addr", ":2381", "interface for gofail's HTTP server")
  29. flag.Parse()
  30. cfg := AgentConfig{
  31. EtcdPath: *etcdPath,
  32. LogDir: *etcdLogDir,
  33. FailpointAddr: *failpointAddr,
  34. UseRoot: *useRoot,
  35. }
  36. if *useRoot && os.Getuid() != 0 {
  37. fmt.Println("got --use-root=true but not root user")
  38. os.Exit(1)
  39. }
  40. if !*useRoot {
  41. fmt.Println("root permissions disabled, agent will not modify network")
  42. }
  43. a, err := newAgent(cfg)
  44. if err != nil {
  45. plog.Fatal(err)
  46. }
  47. a.serveRPC(*port)
  48. var done chan struct{}
  49. <-done
  50. }