Restart Flamenco Manager when the first-time wizard is complete
This commit is contained in:
parent
10f56148d4
commit
38b8220476
@ -77,11 +77,30 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// The main context determines the lifetime of the application. All
|
startFlamenco := true
|
||||||
// long-running goroutines need to keep an eye on this, and stop their work
|
for startFlamenco {
|
||||||
// once it closes.
|
startFlamenco = runFlamencoManager()
|
||||||
mainCtx, mainCtxCancel := context.WithCancel(context.Background())
|
|
||||||
|
|
||||||
|
// After the first run, the first-time wizard should not be forced any more.
|
||||||
|
// If the configuration is still incomplete it can still auto-trigger.
|
||||||
|
cliArgs.firstTimeWizard = false
|
||||||
|
|
||||||
|
if startFlamenco {
|
||||||
|
log.Info().
|
||||||
|
Str("version", appinfo.ApplicationVersion).
|
||||||
|
Str("os", runtime.GOOS).
|
||||||
|
Str("arch", runtime.GOARCH).
|
||||||
|
Msgf("restarting %v", appinfo.ApplicationName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info().Msg("stopping the Flamenco Manager process")
|
||||||
|
}
|
||||||
|
|
||||||
|
// runFlamencoManager starts the entire Flamenco Manager, and only returns after
|
||||||
|
// it has been completely shut down.
|
||||||
|
// Returns true if it should be restarted again.
|
||||||
|
func runFlamencoManager() bool {
|
||||||
// Load configuration.
|
// Load configuration.
|
||||||
configService := config.NewService()
|
configService := config.NewService()
|
||||||
err := configService.Load()
|
err := configService.Load()
|
||||||
@ -106,7 +125,7 @@ func main() {
|
|||||||
log.Error().Err(err).Msg("could not write configuration file")
|
log.Error().Err(err).Msg("could not write configuration file")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: enable TLS via Let's Encrypt.
|
// TODO: enable TLS via Let's Encrypt.
|
||||||
@ -149,6 +168,11 @@ func main() {
|
|||||||
configService.Get().WorkerTimeout,
|
configService.Get().WorkerTimeout,
|
||||||
timeService, persist, taskStateMachine, logStorage, webUpdater)
|
timeService, persist, taskStateMachine, logStorage, webUpdater)
|
||||||
|
|
||||||
|
// The main context determines the lifetime of the application. All
|
||||||
|
// long-running goroutines need to keep an eye on this, and stop their work
|
||||||
|
// once it closes.
|
||||||
|
mainCtx, mainCtxCancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
installSignalHandler(mainCtxCancel)
|
installSignalHandler(mainCtxCancel)
|
||||||
|
|
||||||
// Before doing anything new, clean up in case we made a mess in an earlier run.
|
// Before doing anything new, clean up in case we made a mess in an earlier run.
|
||||||
@ -201,8 +225,16 @@ func main() {
|
|||||||
go openWebbrowser(mainCtx, urls[0])
|
go openWebbrowser(mainCtx, urls[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow the Flamenco API itself trigger a shutdown as well.
|
||||||
|
log.Debug().Msg("waiting for a shutdown request from Flamenco")
|
||||||
|
doRestart := flamenco.WaitForShutdown(mainCtx)
|
||||||
|
log.Info().Bool("willRestart", doRestart).Msg("going to shut down the service")
|
||||||
|
mainCtxCancel()
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
log.Info().Msg("shutdown complete")
|
log.Info().Bool("willRestart", doRestart).Msg("Flamenco Manager service shut down")
|
||||||
|
|
||||||
|
return doRestart
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildFlamencoAPI(
|
func buildFlamencoAPI(
|
||||||
@ -215,7 +247,7 @@ func buildFlamencoAPI(
|
|||||||
webUpdater *webupdates.BiDirComms,
|
webUpdater *webupdates.BiDirComms,
|
||||||
lastRender *last_rendered.LastRenderedProcessor,
|
lastRender *last_rendered.LastRenderedProcessor,
|
||||||
localStorage local_storage.StorageInfo,
|
localStorage local_storage.StorageInfo,
|
||||||
) api.ServerInterface {
|
) *api_impl.Flamenco {
|
||||||
compiler, err := job_compilers.Load(timeService)
|
compiler, err := job_compilers.Load(timeService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("error loading job compilers")
|
log.Fatal().Err(err).Msg("error loading job compilers")
|
||||||
|
@ -4,6 +4,7 @@ package api_impl
|
|||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -30,6 +31,10 @@ type Flamenco struct {
|
|||||||
// the same task. It is also used for certain other queries, like
|
// the same task. It is also used for certain other queries, like
|
||||||
// `MayWorkerRun` to prevent similar race conditions.
|
// `MayWorkerRun` to prevent similar race conditions.
|
||||||
taskSchedulerMutex sync.Mutex
|
taskSchedulerMutex sync.Mutex
|
||||||
|
|
||||||
|
// done is closed by Flamenco when it wants the application to shut down and
|
||||||
|
// restart itself from scratch.
|
||||||
|
done chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ api.ServerInterface = (*Flamenco)(nil)
|
var _ api.ServerInterface = (*Flamenco)(nil)
|
||||||
@ -58,9 +63,29 @@ func NewFlamenco(
|
|||||||
clock: ts,
|
clock: ts,
|
||||||
lastRender: lr,
|
lastRender: lr,
|
||||||
localStorage: localStorage,
|
localStorage: localStorage,
|
||||||
|
|
||||||
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitForShutdown waits until Flamenco wants to shut down the application.
|
||||||
|
// Returns `true` when the application should restart.
|
||||||
|
// Returns `false` when the context closes.
|
||||||
|
func (f *Flamenco) WaitForShutdown(ctx context.Context) bool {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return false
|
||||||
|
case <-f.done:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// requestShutdown closes the 'done' channel, signalling to callers of
|
||||||
|
// WaitForShutdown() that a shutdown is requested.
|
||||||
|
func (f *Flamenco) requestShutdown() {
|
||||||
|
close(f.done)
|
||||||
|
}
|
||||||
|
|
||||||
// sendAPIError wraps sending of an error in the Error format, and
|
// sendAPIError wraps sending of an error in the Error format, and
|
||||||
// handling the failure to marshal that.
|
// handling the failure to marshal that.
|
||||||
func sendAPIError(e echo.Context, code int, message string, args ...interface{}) error {
|
func sendAPIError(e echo.Context, code int, message string, args ...interface{}) error {
|
||||||
|
@ -292,6 +292,10 @@ func (f *Flamenco) SaveWizardConfig(e echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.Info().Msg("first-time wizard: updating configuration")
|
logger.Info().Msg("first-time wizard: updating configuration")
|
||||||
|
|
||||||
|
// Request the shutdown in a goroutine, so that this one can continue sending the response.
|
||||||
|
go f.requestShutdown()
|
||||||
|
|
||||||
return e.NoContent(http.StatusNoContent)
|
return e.NoContent(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user