This commit is contained in:
parent
28a4f4121e
commit
98191fd098
7 changed files with 112 additions and 11 deletions
42
main.go
42
main.go
|
@ -4,12 +4,14 @@ package main
|
|||
import (
|
||||
"embed"
|
||||
"flag"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"git.mstar.dev/mstar/goutils/other"
|
||||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
"github.com/mstarongithub/passkey"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
|
||||
|
@ -21,6 +23,7 @@ import (
|
|||
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||
"git.mstar.dev/mstar/linstrom/storage/cache"
|
||||
webdebug "git.mstar.dev/mstar/linstrom/web/debug"
|
||||
webpublic "git.mstar.dev/mstar/linstrom/web/public"
|
||||
)
|
||||
|
||||
// TODO: Add frontend overwrite
|
||||
|
@ -38,7 +41,20 @@ var defaultDuck string
|
|||
func main() {
|
||||
other.SetupFlags()
|
||||
flag.Parse()
|
||||
other.ConfigureLogging(nil)
|
||||
logfile := getLogFilePathOrNil()
|
||||
if logfile == nil {
|
||||
other.ConfigureLogging(nil)
|
||||
log.Warn().Msg("Can't write to target logfile, not creating one")
|
||||
} else {
|
||||
other.ConfigureLogging(&lumberjack.Logger{
|
||||
Filename: *logfile,
|
||||
MaxSize: 500, // Megabytes
|
||||
MaxBackups: 3,
|
||||
MaxAge: 3, // Days
|
||||
Compress: false,
|
||||
})
|
||||
log.Info().Str("logfile", *logfile).Msg("Logging to stderr and logfile")
|
||||
}
|
||||
if err := config.ReadAndWriteToGlobal(*shared.FlagConfigFile); err != nil {
|
||||
log.Fatal().
|
||||
Err(err).
|
||||
|
@ -59,6 +75,16 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func getLogFilePathOrNil() *string {
|
||||
logfile := *shared.FlagLogFile
|
||||
logPath := path.Dir(logfile)
|
||||
if shared.IsWritable(logPath) {
|
||||
return &logfile
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func oldServer() {
|
||||
storageCache, err := cache.NewCache(
|
||||
config.GlobalConfig.Storage.MaxInMemoryCacheSize,
|
||||
|
@ -126,10 +152,14 @@ func newServer() {
|
|||
log.Fatal().Err(err).Msg("Failed to insert self properly")
|
||||
}
|
||||
if *shared.FlagStartDebugServer {
|
||||
log.Info().Msg("Starting debug server")
|
||||
// TODO: Move into goroutine once public server also exists
|
||||
if err = webdebug.New().Start(); err != nil {
|
||||
log.Fatal().Err(err).Msg("Debug server failed")
|
||||
}
|
||||
go func() {
|
||||
log.Info().Msg("Starting debug server")
|
||||
if err = webdebug.New().Start(); err != nil {
|
||||
log.Fatal().Err(err).Msg("Debug server failed")
|
||||
}
|
||||
}()
|
||||
}
|
||||
log.Info().Msg("Starting public server")
|
||||
public := webpublic.New(":8080")
|
||||
public.Start()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue