mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix(webconsole): use common options (#19329)
This commit is contained in:
@@ -23,7 +23,6 @@ import (
|
||||
|
||||
"yunion.io/x/log"
|
||||
|
||||
common_app "yunion.io/x/onecloud/pkg/cloudcommon/app"
|
||||
"yunion.io/x/onecloud/pkg/cloudproxy/agent/worker"
|
||||
"yunion.io/x/onecloud/pkg/cloudproxy/options"
|
||||
"yunion.io/x/onecloud/pkg/cloudproxy/service"
|
||||
@@ -33,42 +32,29 @@ import (
|
||||
func main() {
|
||||
defer atexit.Handle()
|
||||
|
||||
nop := true
|
||||
wg := &sync.WaitGroup{}
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "wg", wg)
|
||||
ctx, cancelFunc := context.WithCancel(ctx)
|
||||
|
||||
var (
|
||||
opts = options.Get()
|
||||
commonOpts = &opts.CommonOptions
|
||||
opts = options.Get()
|
||||
)
|
||||
if opts.EnableAPIServer || opts.EnableProxyAgent {
|
||||
common_app.InitAuth(commonOpts, func() {
|
||||
log.Infof("Auth complete")
|
||||
})
|
||||
}
|
||||
|
||||
if opts.EnableAPIServer {
|
||||
nop = false
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
service.StartService()
|
||||
}()
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
service.StartService()
|
||||
}()
|
||||
|
||||
if opts.EnableProxyAgent {
|
||||
if opts.EnableAPIServer {
|
||||
const d = "10m"
|
||||
log.Infof("set proxy_agent_init_wait to %s", d)
|
||||
opts.Options.ProxyAgentInitWait = d
|
||||
}
|
||||
const d = "10m"
|
||||
log.Infof("set proxy_agent_init_wait to %s", d)
|
||||
opts.Options.ProxyAgentInitWait = d
|
||||
if err := opts.Options.ValidateThenInit(); err != nil {
|
||||
log.Fatalf("proxy agent options validation: %v", err)
|
||||
}
|
||||
worker := worker.NewWorker(&opts.CommonOptions, &opts.Options)
|
||||
nop = false
|
||||
go func() {
|
||||
worker.Start(ctx)
|
||||
pid := os.Getpid()
|
||||
@@ -79,17 +65,13 @@ func main() {
|
||||
p.Signal(syscall.SIGTERM)
|
||||
}()
|
||||
}
|
||||
if nop {
|
||||
log.Warningln("nothing to do. Please check configuration")
|
||||
} else {
|
||||
go func() {
|
||||
sigChan := make(chan os.Signal)
|
||||
signal.Notify(sigChan, syscall.SIGINT)
|
||||
signal.Notify(sigChan, syscall.SIGTERM)
|
||||
sig := <-sigChan
|
||||
log.Infof("signal received: %s", sig)
|
||||
cancelFunc()
|
||||
}()
|
||||
wg.Wait()
|
||||
}
|
||||
go func() {
|
||||
sigChan := make(chan os.Signal)
|
||||
signal.Notify(sigChan, syscall.SIGINT)
|
||||
signal.Notify(sigChan, syscall.SIGTERM)
|
||||
sig := <-sigChan
|
||||
log.Infof("signal received: %s", sig)
|
||||
cancelFunc()
|
||||
}()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/choices"
|
||||
)
|
||||
|
||||
const (
|
||||
SERVICE_TYPE = "cloudproxy"
|
||||
SERVICE_VERSION = ""
|
||||
)
|
||||
|
||||
const (
|
||||
PM_SCOPE_VPC = "vpc"
|
||||
PM_SCOPE_NETWORK = "network"
|
||||
|
||||
@@ -18,12 +18,12 @@ import (
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/cloudproxy"
|
||||
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
|
||||
agent_options "yunion.io/x/onecloud/pkg/cloudproxy/agent/options"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
EnableAPIServer bool
|
||||
EnableProxyAgent bool
|
||||
|
||||
common_options.CommonOptions
|
||||
@@ -43,8 +43,24 @@ func Get() *Options {
|
||||
&opts,
|
||||
os.Args,
|
||||
"cloudproxy.conf",
|
||||
"cloudproxy",
|
||||
api.SERVICE_TYPE,
|
||||
)
|
||||
})
|
||||
return &opts
|
||||
}
|
||||
|
||||
func OnOptionsChange(oldO, newO interface{}) bool {
|
||||
oldOpts := oldO.(*Options)
|
||||
newOpts := newO.(*Options)
|
||||
|
||||
changed := false
|
||||
if common_options.OnCommonOptionsChange(&oldOpts.CommonOptions, &newOpts.CommonOptions) {
|
||||
changed = true
|
||||
}
|
||||
|
||||
if common_options.OnDBOptionsChange(&oldOpts.DBOptions, &newOpts.DBOptions) {
|
||||
changed = true
|
||||
}
|
||||
|
||||
return changed
|
||||
}
|
||||
|
||||
@@ -18,13 +18,16 @@ import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
_ "yunion.io/x/sqlchemy/backends"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/cloudproxy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon"
|
||||
app_common "yunion.io/x/onecloud/pkg/cloudcommon/app"
|
||||
common_app "yunion.io/x/onecloud/pkg/cloudcommon/app"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
|
||||
"yunion.io/x/onecloud/pkg/cloudproxy/models"
|
||||
"yunion.io/x/onecloud/pkg/cloudproxy/options"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
@@ -32,12 +35,19 @@ import (
|
||||
|
||||
func StartService() {
|
||||
var (
|
||||
opts = options.Get()
|
||||
dbOpts = &opts.DBOptions
|
||||
baseOpts = &opts.BaseOptions
|
||||
opts = options.Get()
|
||||
dbOpts = &opts.DBOptions
|
||||
baseOpts = &opts.BaseOptions
|
||||
commonOpts = &opts.CommonOptions
|
||||
)
|
||||
|
||||
app := app_common.InitApp(baseOpts, true).
|
||||
common_app.InitAuth(commonOpts, func() {
|
||||
log.Infof("Auth complete")
|
||||
})
|
||||
|
||||
common_options.StartOptionManager(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, api.SERVICE_VERSION, options.OnOptionsChange)
|
||||
|
||||
app := common_app.InitApp(baseOpts, true).
|
||||
OnException(func(method, path string, body jsonutils.JSONObject, err error) {
|
||||
ctx := context.Background()
|
||||
session := auth.GetAdminSession(ctx, baseOpts.Region)
|
||||
@@ -51,5 +61,5 @@ func StartService() {
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
defer cloudcommon.CloseDB()
|
||||
|
||||
app_common.ServeForever(app, baseOpts)
|
||||
common_app.ServeForever(app, baseOpts)
|
||||
}
|
||||
|
||||
@@ -61,6 +61,12 @@ func StartService() {
|
||||
// log.Fatalf("glance service must running with root permissions")
|
||||
// }
|
||||
|
||||
app_common.InitAuth(commonOpts, func() {
|
||||
log.Infof("Auth complete!!")
|
||||
})
|
||||
|
||||
common_options.StartOptionManager(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, api.SERVICE_VERSION, options.OnOptionsChange)
|
||||
|
||||
if opts.PortV2 > 0 {
|
||||
log.Infof("Port V2 %d is specified, use v2 port", opts.PortV2)
|
||||
opts.Port = opts.PortV2
|
||||
@@ -96,10 +102,6 @@ func StartService() {
|
||||
|
||||
log.Infof("Target image formats %#v", opts.TargetImageFormats)
|
||||
|
||||
app_common.InitAuth(commonOpts, func() {
|
||||
log.Infof("Auth complete!!")
|
||||
})
|
||||
|
||||
if ok, err := hasVmwareAccount(); err != nil {
|
||||
log.Errorf("failed get vmware cloudaccounts")
|
||||
} else if ok {
|
||||
@@ -122,8 +124,6 @@ func StartService() {
|
||||
|
||||
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
|
||||
|
||||
common_options.StartOptionManager(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, api.SERVICE_VERSION, options.OnOptionsChange)
|
||||
|
||||
models.Init(options.Options.StorageDriver)
|
||||
|
||||
if len(options.Options.DeployServerSocketPath) > 0 {
|
||||
|
||||
@@ -41,18 +41,18 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/webconsole/server"
|
||||
)
|
||||
|
||||
func ensureBinExists(binPath string) {
|
||||
if _, err := os.Stat(binPath); os.IsNotExist(err) {
|
||||
log.Fatalf("Binary %s not exists", binPath)
|
||||
}
|
||||
}
|
||||
|
||||
func StartService() {
|
||||
|
||||
opts := &o.Options
|
||||
commonOpts := &o.Options.CommonOptions
|
||||
common_options.ParseOptions(opts, os.Args, "webconsole.conf", api.SERVICE_TYPE)
|
||||
|
||||
app_common.InitAuth(commonOpts, func() {
|
||||
log.Infof("Auth complete")
|
||||
})
|
||||
|
||||
common_options.StartOptionManager(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, api.SERVICE_VERSION, o.OnOptionsChange)
|
||||
|
||||
if opts.ApiServer == "" {
|
||||
log.Fatalf("--api-server must specified")
|
||||
}
|
||||
@@ -61,16 +61,6 @@ func StartService() {
|
||||
log.Fatalf("invalid --api-server %s", opts.ApiServer)
|
||||
}
|
||||
|
||||
for _, binPath := range []string{opts.IpmitoolPath} {
|
||||
ensureBinExists(binPath)
|
||||
}
|
||||
|
||||
app_common.InitAuth(commonOpts, func() {
|
||||
log.Infof("Auth complete")
|
||||
})
|
||||
|
||||
common_options.StartOptionManager(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, api.SERVICE_VERSION, o.OnOptionsChange)
|
||||
|
||||
registerSigTraps()
|
||||
start()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user