main.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 etcdmain
  15. import (
  16. "fmt"
  17. "os"
  18. "strings"
  19. "github.com/coreos/go-systemd/daemon"
  20. systemdutil "github.com/coreos/go-systemd/util"
  21. )
  22. func Main() {
  23. checkSupportArch()
  24. if len(os.Args) > 1 {
  25. cmd := os.Args[1]
  26. if covArgs := os.Getenv("ETCDCOV_ARGS"); len(covArgs) > 0 {
  27. args := strings.Split(os.Getenv("ETCDCOV_ARGS"), "\xe7\xcd")[1:]
  28. rootCmd.SetArgs(args)
  29. cmd = "grpc-proxy"
  30. }
  31. switch cmd {
  32. case "gateway", "grpc-proxy":
  33. if err := rootCmd.Execute(); err != nil {
  34. fmt.Fprint(os.Stderr, err)
  35. os.Exit(1)
  36. }
  37. return
  38. }
  39. }
  40. startEtcdOrProxyV2()
  41. }
  42. func notifySystemd() {
  43. if !systemdutil.IsRunningSystemd() {
  44. return
  45. }
  46. sent, err := daemon.SdNotify(false, "READY=1")
  47. if err != nil {
  48. plog.Errorf("failed to notify systemd for readiness: %v", err)
  49. }
  50. if !sent {
  51. plog.Errorf("forgot to set Type=notify in systemd service file?")
  52. }
  53. }