service.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. _ "yunion.io/x/sqlchemy/backends"
  19. "yunion.io/x/onecloud/pkg/ansibleserver/models"
  20. "yunion.io/x/onecloud/pkg/ansibleserver/options"
  21. "yunion.io/x/onecloud/pkg/cloudcommon"
  22. common_app "yunion.io/x/onecloud/pkg/cloudcommon/app"
  23. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  24. common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
  25. )
  26. func StartService() {
  27. opts := &options.Options
  28. common_options.ParseOptions(opts, os.Args, "ansibleserver.conf", "ansibleserver")
  29. commonOpts := &opts.CommonOptions
  30. common_app.InitAuth(commonOpts, func() {
  31. log.Infof("Auth complete")
  32. })
  33. dbOpts := &opts.DBOptions
  34. baseOpts := &opts.BaseOptions
  35. models.InitPlaybookWorker()
  36. app := common_app.InitApp(baseOpts, false)
  37. cloudcommon.InitDB(dbOpts)
  38. InitHandlers(app, opts.IsSlaveNode)
  39. db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
  40. defer cloudcommon.CloseDB()
  41. common_app.ServeForever(app, baseOpts)
  42. }