mirror of
https://github.com/Cernobor/oko-server.git
synced 2025-02-24 08:27:17 +00:00
db reinitialization flag
This commit is contained in:
parent
b512bc0d2f
commit
7471c89143
3
main.go
3
main.go
@ -16,6 +16,7 @@ func main() {
|
|||||||
dbFileArg := flag.String("dbfile", "./data.sqlite3", "File that holds the server's sqlite3 database. Will be created if it does not exist. Default is \"./data.sqlite3\".")
|
dbFileArg := flag.String("dbfile", "./data.sqlite3", "File that holds the server's sqlite3 database. Will be created if it does not exist. Default is \"./data.sqlite3\".")
|
||||||
tilepackFileArg := flag.String("tilepack", "", "File that will be sent to clients when they request a tile pack. Required.")
|
tilepackFileArg := flag.String("tilepack", "", "File that will be sent to clients when they request a tile pack. Required.")
|
||||||
apkFileArg := flag.String("apk", "", "APK file with the client app. If not specified, no APK will be available (404).")
|
apkFileArg := flag.String("apk", "", "APK file with the client app. If not specified, no APK will be available (404).")
|
||||||
|
reinitDBArg := flag.Bool("reinit-db", false, "Reinitializes the DB, which means all the tables will be recreated, deleting all data.")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := server.New(*dbFileArg, *tilepackFileArg, *apkFileArg)
|
s := server.New(*dbFileArg, *tilepackFileArg, *apkFileArg, *reinitDBArg)
|
||||||
|
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
|
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
|
||||||
|
@ -35,14 +35,16 @@ type ServerConfig struct {
|
|||||||
DbPath string
|
DbPath string
|
||||||
TilepackPath string
|
TilepackPath string
|
||||||
ApkPath string
|
ApkPath string
|
||||||
|
ReinitDB bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(dbPath, tilepackPath, apkPath string) *Server {
|
func New(dbPath, tilepackPath, apkPath string, reinitDB bool) *Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
config: ServerConfig{
|
config: ServerConfig{
|
||||||
DbPath: dbPath,
|
DbPath: dbPath,
|
||||||
TilepackPath: tilepackPath,
|
TilepackPath: tilepackPath,
|
||||||
ApkPath: apkPath,
|
ApkPath: apkPath,
|
||||||
|
ReinitDB: reinitDB,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,7 +54,7 @@ func (s *Server) Run(ctx context.Context) {
|
|||||||
s.log.SetLevel(logrus.DebugLevel)
|
s.log.SetLevel(logrus.DebugLevel)
|
||||||
|
|
||||||
s.ctx = ctx
|
s.ctx = ctx
|
||||||
s.setupDB(true)
|
s.setupDB()
|
||||||
s.setupTiles()
|
s.setupTiles()
|
||||||
|
|
||||||
router := s.setupRouter()
|
router := s.setupRouter()
|
||||||
@ -89,14 +91,14 @@ func (s *Server) getDbConn() *sqlite.Conn {
|
|||||||
return conn
|
return conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) setupDB(reinit bool) {
|
func (s *Server) setupDB() {
|
||||||
dbpool, err := sqlitex.Open(fmt.Sprintf("file:%s", s.config.DbPath), 0, 10)
|
dbpool, err := sqlitex.Open(fmt.Sprintf("file:%s", s.config.DbPath), 0, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.WithError(err).Fatal("Failed to open/create DB.")
|
s.log.WithError(err).Fatal("Failed to open/create DB.")
|
||||||
}
|
}
|
||||||
s.dbpool = dbpool
|
s.dbpool = dbpool
|
||||||
|
|
||||||
if reinit {
|
if s.config.ReinitDB {
|
||||||
conn := s.getDbConn()
|
conn := s.getDbConn()
|
||||||
defer s.dbpool.Put(conn)
|
defer s.dbpool.Put(conn)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user