move ConfigLoad into Start function when running as a service (take 2)

This commit is contained in:
Alison Winters 2019-10-30 21:34:00 +08:00 committed by Frank Denis
parent b80e4957d1
commit 7307c51d6f

View file

@ -25,6 +25,7 @@ type App struct {
wg sync.WaitGroup wg sync.WaitGroup
quit chan struct{} quit chan struct{}
proxy *Proxy proxy *Proxy
flags *ConfigFlags
} }
func main() { func main() {
@ -71,6 +72,7 @@ func main() {
app := &App{ app := &App{
quit: make(chan struct{}), quit: make(chan struct{}),
flags: &flags,
} }
svc, err := service.New(app, svcConfig) svc, err := service.New(app, svcConfig)
if err != nil { if err != nil {
@ -79,9 +81,6 @@ func main() {
} }
app.proxy = NewProxy() app.proxy = NewProxy()
_ = ServiceManagerStartNotify() _ = ServiceManagerStartNotify()
if err := ConfigLoad(app.proxy, &flags); err != nil {
dlog.Fatal(err)
}
if len(*svcFlag) != 0 { if len(*svcFlag) != 0 {
if svc == nil { if svc == nil {
dlog.Fatal("Built-in service installation is not supported on this platform") dlog.Fatal("Built-in service installation is not supported on this platform")
@ -108,6 +107,9 @@ func main() {
dlog.Fatal(err) dlog.Fatal(err)
} }
} else { } else {
if err := ConfigLoad(app.proxy, &flags); err != nil {
dlog.Fatal(err)
}
app.signalWatch() app.signalWatch()
app.Start(nil) app.Start(nil)
} }
@ -116,10 +118,15 @@ func main() {
} }
func (app *App) Start(service service.Service) error { func (app *App) Start(service service.Service) error {
go func() {
if err := ConfigLoad(app.proxy, app.flags); err != nil {
dlog.Fatal(err)
}
if err := app.proxy.InitPluginsGlobals(); err != nil { if err := app.proxy.InitPluginsGlobals(); err != nil {
dlog.Fatal(err) dlog.Fatal(err)
} }
go app.appMain() app.appMain()
}()
return nil return nil
} }