fix(config-watcher): start only if config-directory exists (#1854)

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto 2024-03-18 19:14:48 +01:00 committed by GitHub
parent 843f93e1ab
commit a046dcac5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 4 deletions

13
main.go
View File

@ -306,11 +306,16 @@ For a list of compatible model, check out: https://localai.io/model-compatibilit
return fmt.Errorf("failed basic startup tasks with error %s", err.Error())
}
closeConfigWatcherFn, err := startup.WatchConfigDirectory(ctx.String("localai-config-dir"), options)
defer closeConfigWatcherFn()
configdir := ctx.String("localai-config-dir")
// Watch the configuration directory
// If the directory does not exist, we don't watch it
if _, err := os.Stat(configdir); err == nil {
closeConfigWatcherFn, err := startup.WatchConfigDirectory(ctx.String("localai-config-dir"), options)
defer closeConfigWatcherFn()
if err != nil {
return fmt.Errorf("failed while watching configuration directory %s", ctx.String("localai-config-dir"))
if err != nil {
return fmt.Errorf("failed while watching configuration directory %s", ctx.String("localai-config-dir"))
}
}
appHTTP, err := http.App(cl, ml, options)