service.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2019 Yunion
  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 service
  15. import (
  16. "os"
  17. "yunion.io/x/log"
  18. app_common "yunion.io/x/onecloud/pkg/cloudcommon/app"
  19. "yunion.io/x/onecloud/pkg/cloudcommon/etcd"
  20. common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
  21. "yunion.io/x/onecloud/pkg/cloudir/options"
  22. )
  23. func StartService() {
  24. opts := &options.Options
  25. baseOpts := &opts.BaseOptions
  26. commonOpts := &opts.CommonOptions
  27. common_options.ParseOptions(opts, os.Args, "cloudir.conf", "cloudir")
  28. app_common.InitAuth(commonOpts, func() {
  29. log.Infof("Auth complete!!")
  30. })
  31. err := etcd.InitDefaultEtcdClient(&opts.SEtcdOptions, nil)
  32. if err != nil {
  33. log.Fatalf("init etcd fail: %s", err)
  34. return
  35. }
  36. app := app_common.InitApp(baseOpts, false)
  37. initHandlers(app, opts.IsSlaveNode)
  38. app_common.ServeForeverWithCleanup(app, baseOpts, func() {
  39. etcd.CloseDefaultEtcdClient()
  40. })
  41. }