main.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. "go.uber.org/zap"
  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(lg *zap.Logger) {
  43. _, err := daemon.SdNotify(false, daemon.SdNotifyReady)
  44. if err != nil {
  45. if lg != nil {
  46. lg.Error("failed to notify systemd for readiness", zap.Error(err))
  47. } else {
  48. plog.Errorf("failed to notify systemd for readiness: %v", err)
  49. }
  50. }
  51. }