some bug fixes

This commit is contained in:
ston1th 2019-05-05 19:06:51 +02:00
commit 0e914c629e
16 changed files with 179 additions and 52 deletions

View file

@ -4,9 +4,11 @@ package cmd
import (
"encoding/json"
"errors"
"git.giftfish.de/ston1th/docstore/pkg/core"
"git.giftfish.de/ston1th/docstore/pkg/db"
"git.giftfish.de/ston1th/docstore/pkg/log"
"git.giftfish.de/ston1th/docstore/pkg/scan"
"git.giftfish.de/ston1th/docstore/pkg/server"
"git.giftfish.de/ston1th/godrop/v2"
"github.com/urfave/cli"
@ -26,6 +28,8 @@ const (
defRunUser = "docstore"
defRunGroup = "docstore"
defTimeout = 600
)
var (
@ -55,7 +59,7 @@ func initServer(cfg core.Config) (err error) {
return
}
if err = godrop.PledgePromises("stdio rpath wpath cpath inet fattr flock unveil"); err != nil {
if err = godrop.PledgePromises("stdio rpath wpath cpath inet fattr flock proc exec unveil"); err != nil {
return
}
@ -64,6 +68,14 @@ func initServer(cfg core.Config) (err error) {
return
}
log.InitLogger(cfg)
cfg.DataDir = filepath.Join(cfg.RunDir, core.DataDir)
scanner, err := scan.New(cfg.DataDir, cfg.Langs, time.Second*time.Duration(cfg.CMDTimeout))
if err != nil {
return errors.New("scanner: " + err.Error())
}
err = godrop.Unveil(cfg.RunDir, "rwc")
if err != nil {
return
@ -73,10 +85,7 @@ func initServer(cfg core.Config) (err error) {
return
}
log.InitLogger(cfg)
cfg.DataDir = filepath.Join(cfg.RunDir, core.DataDir)
srv := server.NewHTTPServer(cfg, l)
srv := server.NewHTTPServer(cfg, l, scanner)
err = srv.Start()
if err != nil {
return
@ -124,6 +133,7 @@ func Run(version string) {
Usage: "start docstore server",
Flags: defaultFlags(serverFlags()),
Action: func(c *cli.Context) error {
config.Langs = c.StringSlice("langs")
if err := loadConfig(); err != nil {
stdlog.Fatal("server: ", err)
}
@ -235,6 +245,16 @@ func serverFlags() []cli.Flag {
Usage: "static hmac secret (at least 64 chars, used for JWT signing)",
Destination: &config.Secret,
},
cli.StringSliceFlag{
Name: "langs",
Usage: "languages for tesseract ocr",
},
cli.IntFlag{
Name: "timeout, t",
Value: defTimeout,
Usage: "timeout in seconds for executed teseract and pdftotext commands",
Destination: &config.CMDTimeout,
},
cli.BoolFlag{
Name: "foreground, f",
Usage: "do not fork into the background",