Changeset 63 in code for trunk


Ignore:
Timestamp:
Jan 21, 2024, 3:23:44 AM (17 months ago)
Author:
yakumo.izuru
Message:

今すぐv1をリリースすべきでしょうか?

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r61 r63  
    11PREFIX ?= /usr/local
     2GOFLAGS ?= -v -ldflags "-w -X `go list`.Version=${VERSION} -X `go list`.Commit=${COMMIT}"
     3VERSION = `git describe --abbrev=0 --tags 2>/dev/null || echo "VERSION"`
     4COMMIT = `git rev-parse --short HEAD || echo "COMMIT"`
    25
    36build:
    4         go build -v ./cmd/mai
     7        go build ${GOFLAGS} ./cmd/mai
    58clean:
    69        rm -f mai
  • trunk/cmd/mai/flag.go

    r59 r63  
    88func parseFlags() {
    99        flag.StringVar(&configfile, "f", "", "Configuration file")
     10        flag.BoolVar(&verbose, "v", false, "Verbose logging")
    1011        flag.Parse()
    1112}
  • trunk/cmd/mai/main.go

    r62 r63  
    33import (
    44        "bytes"
     5        "fmt"
    56        "net/http"
    67        "net/url"
     
    89        "time"
    910        "runtime"
    10 
     11        "syscall"
     12
     13        "marisa.chaotic.ninja/mai"
    1114        "marisa.chaotic.ninja/mai/engines"
     15
    1216        "github.com/gofiber/fiber/v2"
    1317        "github.com/gofiber/fiber/v2/middleware/logger"
     
    1721var (
    1822        configfile string
     23        verbose bool
    1924)
    2025var conf struct {
     26        group string
    2127        listen string
    22         redisuri string
    2328        staticpath string
    2429        tmplpath string
     30        user string
    2531}
    2632func main() {
     
    2834
    2935        if configfile != "" {
     36                if verbose {
     37                        fmt.Printf("[mai] Reading configuration file")
     38                }
    3039                readConf(configfile)
    3140        }
     
    3544        conf.staticpath = "./static"
    3645        conf.tmplpath = "./views"
     46
     47        if conf.user != "" {
     48                if verbose {
     49                        fmt.Printf("[mai] Dropping privileges to %s", conf.user)
     50                }
     51                uid, gid, err := usergroupids(conf.user, conf.group)
     52                if err != nil {
     53                        fmt.Println(err)
     54                        os.Exit(1)
     55                }
     56                syscall.Setuid(uid)
     57                syscall.Setgid(gid)
     58        }
    3759       
    3860        engine := html.New(conf.tmplpath, ".html")
     
    266288        })
    267289        app.Listen(conf.listen)
     290
     291        if verbose {
     292                fmt.Printf("Starting mai %v\n", mai.FullVersion())
     293                fmt.Printf("Listening on %s", conf.listen)
     294        }
    268295}
  • trunk/cmd/mai/readconf.go

    r61 r63  
    1212        }
    1313
     14        conf.group = cfg.Section("mai").Key("group").String()
    1415        conf.listen = cfg.Section("mai").Key("listen").String()
    1516        conf.staticpath = cfg.Section("mai").Key("static").String()
    1617        conf.tmplpath = cfg.Section("mai").Key("templates").String()
     18        conf.user = cfg.Section("mai").Key("user").String()
    1719
    1820        return nil
  • trunk/mai.ini.5

    r61 r63  
    88.Ss [mai] section
    99.Bl -tag -width 11n
     10.It group
     11Group ID for dropping privileges to.
     12If unset, assume the GID of user
    1013.It listen
    1114HTTP port for the server to listen.
     
    1720Directory where the templates are located.
    1821Default is "./views"
     22.It user
     23User ID for dropping privileges to.
    1924.El
    2025.Sh ENVIRONMENT
Note: See TracChangeset for help on using the changeset viewer.