service.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/cloudmux/pkg/multicloud/loader"
  18. "yunion.io/x/log"
  19. _ "yunion.io/x/sqlchemy/backends"
  20. api "yunion.io/x/onecloud/pkg/apis/s3gateway"
  21. "yunion.io/x/onecloud/pkg/cloudcommon"
  22. app_common "yunion.io/x/onecloud/pkg/cloudcommon/app"
  23. common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
  24. "yunion.io/x/onecloud/pkg/s3gateway/handlers"
  25. "yunion.io/x/onecloud/pkg/s3gateway/options"
  26. )
  27. func StartService() {
  28. opts := &options.Options
  29. commonOpts := &opts.CommonOptions
  30. baseOpts := &opts.BaseOptions
  31. common_options.ParseOptions(opts, os.Args, "s3gateway.conf", api.SERVICE_TYPE)
  32. app_common.InitAuth(commonOpts, func() {
  33. log.Infof("Auth complete!!")
  34. })
  35. app := app_common.InitApp(&opts.BaseOptions, false)
  36. handlers.InitHandlers(app)
  37. /*if !opts.IsSlaveNode {
  38. cron := cronman.GetCronJobManager(true)
  39. cron.AddJobAtIntervals("CleanPendingDeleteImages", time.Duration(options.Options.PendingDeleteCheckSeconds)*time.Second, models.ImageManager.CleanPendingDeleteImages)
  40. cron.AddJobAtIntervals("CalculateQuotaUsages", time.Duration(opts.CalculateQuotaUsageIntervalSeconds)*time.Second, models.QuotaManager.CalculateQuotaUsages)
  41. cron.Start()
  42. }*/
  43. //cloudcommon.AppDBInit(app)
  44. app_common.ServeForeverWithCleanup(app, baseOpts, func() {
  45. cloudcommon.CloseDB()
  46. })
  47. }