mirror of
https://github.com/datarhei/core.git
synced 2025-09-26 20:11:29 +08:00
Add v16.7.2
This commit is contained in:
56
main.go
Normal file
56
main.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"github.com/datarhei/core/app/api"
|
||||
"github.com/datarhei/core/log"
|
||||
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger := log.New("Core").WithOutput(log.NewConsoleWriter(os.Stderr, log.Lwarn, true))
|
||||
|
||||
app, err := api.New(os.Getenv("CORE_CONFIGFILE"), os.Stderr)
|
||||
if err != nil {
|
||||
logger.Error().WithError(err).Log("Failed to create new API")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
if proc, err := os.FindProcess(os.Getpid()); err == nil {
|
||||
proc.Signal(os.Interrupt)
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
if err := app.Start(); err != api.ErrConfigReload {
|
||||
if err != nil {
|
||||
logger.Error().WithError(err).Log("Failed to start API")
|
||||
}
|
||||
|
||||
break
|
||||
} else {
|
||||
logger.Warn().WithError(err).Log("Config reload requested")
|
||||
}
|
||||
|
||||
app.Stop()
|
||||
|
||||
if err := app.Reload(); err != nil {
|
||||
logger.Error().WithError(err).Log("Failed to reload config")
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for interrupt signal to gracefully shutdown the app
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, os.Interrupt)
|
||||
<-quit
|
||||
|
||||
// Stop the app
|
||||
app.Destroy()
|
||||
}
|
Reference in New Issue
Block a user