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
1 changed files with 15 additions and 8 deletions

View File

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