first working version

This commit is contained in:
ston1th 2019-04-28 18:16:40 +02:00
commit de359ab415
47 changed files with 1016 additions and 2012 deletions

View file

@ -14,17 +14,18 @@ import (
"net"
"os"
"os/signal"
"path/filepath"
"syscall"
"time"
)
const (
defDataDir = "/var/lib/docstore"
defRunDir = "/var/lib/docstore"
defListen = "127.0.0.1:8080"
defLogFile = "docstore.log"
defRunUser = "wiki"
defRunGroup = "wiki"
defRunUser = "docstore"
defRunGroup = "docstore"
)
var (
@ -50,7 +51,7 @@ func initServer(cfg core.Config) (err error) {
if err != nil {
return
}
if err = os.Chdir(cfg.DataDir); err != nil {
if err = os.Chdir(cfg.RunDir); err != nil {
return
}
@ -65,6 +66,11 @@ func initServer(cfg core.Config) (err error) {
log.InitLogger(cfg)
cfg.DataDir = filepath.Join(cfg.RunDir, core.DataDir)
err = godrop.Unveil(cfg.DataDir, "rwc")
if err != nil {
return
}
srv := server.NewHTTPServer(cfg, l)
err = srv.Start()
if err != nil {
@ -105,7 +111,7 @@ func loadConfig() error {
func Run(version string) {
app := cli.NewApp()
app.Name = "docstore"
app.Usage = "a simple wiki engine"
app.Usage = "file server and indexing engine"
app.Version = version
app.Commands = []cli.Command{
{
@ -125,7 +131,7 @@ func Run(version string) {
},
{
Name: "dump",
Usage: "create a json dump of all articles in the data directory (docstore needs to be stopped)",
Usage: "create a json dump of all users (docstore needs to be stopped)",
Flags: defaultFlags(dumpRestoreFlags()),
Action: func(c *cli.Context) error {
var (
@ -158,7 +164,7 @@ func Run(version string) {
},
{
Name: "restore",
Usage: "restore a json dump to the data directory (docstore needs to be stopped)",
Usage: "restore a json dump (docstore needs to be stopped)",
Flags: defaultFlags(dumpRestoreFlags()),
Action: func(c *cli.Context) error {
var (
@ -224,11 +230,6 @@ func serverFlags() []cli.Flag {
Usage: "static hmac secret (at least 64 chars, used for JWT signing)",
Destination: &config.Secret,
},
cli.BoolTFlag{
Name: "admin, a",
Usage: "use -a=false to disable the admin user",
Destination: &config.Admin,
},
cli.BoolFlag{
Name: "foreground, f",
Usage: "do not fork into the background",
@ -266,10 +267,10 @@ func defaultFlags(f []cli.Flag) []cli.Flag {
Destination: &configFile,
},
cli.StringFlag{
Name: "data, d",
Value: defDataDir,
Usage: "data directory",
Destination: &config.DataDir,
Name: "run, r",
Value: defRunDir,
Usage: "run directory",
Destination: &config.RunDir,
},
}, f...)
}