working commit

This commit is contained in:
2026-06-09 22:33:18 +02:00
parent 56a73e87b6
commit f61b9b87e2
5 changed files with 106 additions and 50 deletions
+11 -29
View File
@@ -1,6 +1,7 @@
package server
import (
"context"
"fmt"
"io/ioutil"
"os"
@@ -8,10 +9,9 @@ import (
"os/user"
"path/filepath"
"strconv"
"sync"
"syscall"
"time"
"context"
"sync"
"mbase/app/config"
"mbase/app/maindb"
@@ -41,40 +41,21 @@ type Server struct {
state descr.Server
sfile string
logf *os.File
ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup
ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup
}
func NewServer() (*Server, error) {
func NewServer(conf *config.Config) (*Server, error) {
var err error
srv := &Server{}
srv := &Server{
conf: conf,
}
srv.log = logger.NewLogger("server")
srv.ctx, srv.cancel = context.WithCancel(context.Background())
return srv, err
}
func (srv *Server) Configure() error {
var err error
srv.conf = config.NewConfig()
err = srv.conf.ReadFile()
if err != nil {
return err
}
err = srv.conf.ReadEnv()
if err != nil {
return err
}
err = srv.conf.ReadOpts()
if err != nil {
return err
}
srv.sfile = filepath.Join(srv.conf.DataDir, "mbase.yaml")
return err
}
func (srv *Server) LoadState() error {
var err error
_, err = os.Stat(srv.sfile)
@@ -125,6 +106,8 @@ func (srv *Server) Build() error {
var err error
srv.log.Infof("Build server")
srv.sfile = filepath.Join(srv.conf.DataDir, "mbase.yaml")
currUser, err := user.Current()
if err != nil {
err = fmt.Errorf("Error getting current user: %v\n", err)
@@ -458,7 +441,6 @@ func (srv *Server) Daemonize() error {
return err
}
func (srv *Server) Rotator() {
srv.wg.Add(1)
var counter uint64