2022-05-11 22:47:31 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"npm/internal/api"
|
|
|
|
"npm/internal/config"
|
|
|
|
"npm/internal/database"
|
2022-07-14 22:52:38 +00:00
|
|
|
"npm/internal/entity/certificate"
|
|
|
|
"npm/internal/entity/host"
|
2022-05-11 22:47:31 +00:00
|
|
|
"npm/internal/entity/setting"
|
2022-07-14 22:52:38 +00:00
|
|
|
"npm/internal/jobqueue"
|
2022-05-11 22:47:31 +00:00
|
|
|
"npm/internal/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
var commit string
|
|
|
|
var version string
|
|
|
|
var sentryDSN string
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
config.InitArgs(&version, &commit)
|
|
|
|
config.Init(&version, &commit, &sentryDSN)
|
|
|
|
|
|
|
|
database.Migrate(func() {
|
|
|
|
setting.ApplySettings()
|
|
|
|
database.CheckSetup()
|
|
|
|
|
2022-07-14 22:52:38 +00:00
|
|
|
// Internal Job Queue
|
|
|
|
jobqueue.Start()
|
|
|
|
certificate.AddPendingJobs()
|
|
|
|
host.AddPendingJobs()
|
|
|
|
|
|
|
|
// Http server
|
2022-05-11 22:47:31 +00:00
|
|
|
api.StartServer()
|
|
|
|
irqchan := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(irqchan, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
|
|
|
for irq := range irqchan {
|
|
|
|
if irq == syscall.SIGINT || irq == syscall.SIGTERM {
|
|
|
|
logger.Info("Got ", irq, " shutting server down ...")
|
|
|
|
// Close db
|
|
|
|
err := database.GetInstance().Close()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("DatabaseCloseError", err)
|
|
|
|
}
|
2022-07-14 22:52:38 +00:00
|
|
|
// nolint
|
|
|
|
jobqueue.Shutdown()
|
2022-05-11 22:47:31 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|