main.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. "go.uber.org/zap"
  22. )
  23. func Main() {
  24. checkSupportArch()
  25. if len(os.Args) > 1 {
  26. cmd := os.Args[1]
  27. if covArgs := os.Getenv("ETCDCOV_ARGS"); len(covArgs) > 0 {
  28. args := strings.Split(os.Getenv("ETCDCOV_ARGS"), "\xe7\xcd")[1:]
  29. rootCmd.SetArgs(args)
  30. cmd = "grpc-proxy"
  31. }
  32. switch cmd {
  33. case "gateway", "grpc-proxy":
  34. if err := rootCmd.Execute(); err != nil {
  35. fmt.Fprint(os.Stderr, err)
  36. os.Exit(1)
  37. }
  38. return
  39. }
  40. }
  41. startEtcdOrProxyV2()
  42. }
  43. func notifySystemd(lg *zap.Logger) {
  44. if !systemdutil.IsRunningSystemd() {
  45. return
  46. }
  47. if lg != nil {
  48. lg.Info("host was booted with systemd, sends READY=1 message to init daemon")
  49. }
  50. sent, err := daemon.SdNotify(false, "READY=1")
  51. if err != nil {
  52. if lg != nil {
  53. lg.Error("failed to notify systemd for readiness", zap.Error(err))
  54. } else {
  55. plog.Errorf("failed to notify systemd for readiness: %v", err)
  56. }
  57. }
  58. if !sent {
  59. if lg != nil {
  60. lg.Warn("forgot to set Type=notify in systemd service file?")
  61. } else {
  62. plog.Errorf("forgot to set Type=notify in systemd service file?")
  63. }
  64. }
  65. }