prefix cmd/gonic conf vars
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
// Package main is the gonic server entrypoint
|
||||||
|
//nolint:lll // flags help strings
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -25,15 +27,16 @@ const (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
set := flag.NewFlagSet(version.NAME, flag.ExitOnError)
|
set := flag.NewFlagSet(version.NAME, flag.ExitOnError)
|
||||||
listenAddr := set.String("listen-addr", "0.0.0.0:4747", "listen address (optional)")
|
confListenAddr := set.String("listen-addr", "0.0.0.0:4747", "listen address (optional)")
|
||||||
musicPath := set.String("music-path", "", "path to music")
|
confMusicPath := set.String("music-path", "", "path to music")
|
||||||
cachePath := set.String("cache-path", "/tmp/gonic_cache", "path to cache")
|
confCachePath := set.String("cache-path", "/tmp/gonic_cache", "path to cache")
|
||||||
dbPath := set.String("db-path", "gonic.db", "path to database (optional)")
|
confDBPath := set.String("db-path", "gonic.db", "path to database (optional)")
|
||||||
scanInterval := set.Int("scan-interval", 0, "interval (in minutes) to automatically scan music (optional)")
|
confScanInterval := set.Int("scan-interval", 0, "interval (in minutes) to automatically scan music (optional)")
|
||||||
jukeboxEnabled := set.Bool("jukebox-enabled", false, "whether the subsonic jukebox api should be enabled (optional)")
|
confJukeboxEnabled := set.Bool("jukebox-enabled", false, "whether the subsonic jukebox api should be enabled (optional)")
|
||||||
proxyPrefix := set.String("proxy-prefix", "", "url path prefix to use if behind proxy. eg '/gonic' (optional)")
|
confProxyPrefix := set.String("proxy-prefix", "", "url path prefix to use if behind proxy. eg '/gonic' (optional)")
|
||||||
|
confShowVersion := set.Bool("version", false, "show gonic version")
|
||||||
_ = set.String("config-path", "", "path to config (optional)")
|
_ = set.String("config-path", "", "path to config (optional)")
|
||||||
showVersion := set.Bool("version", false, "show gonic version")
|
|
||||||
if err := ff.Parse(set, os.Args[1:],
|
if err := ff.Parse(set, os.Args[1:],
|
||||||
ff.WithConfigFileFlag("config-path"),
|
ff.WithConfigFileFlag("config-path"),
|
||||||
ff.WithConfigFileParser(ff.PlainParser),
|
ff.WithConfigFileParser(ff.PlainParser),
|
||||||
@@ -41,55 +44,57 @@ func main() {
|
|||||||
); err != nil {
|
); err != nil {
|
||||||
log.Fatalf("error parsing args: %v\n", err)
|
log.Fatalf("error parsing args: %v\n", err)
|
||||||
}
|
}
|
||||||
//
|
|
||||||
if *showVersion {
|
if *confShowVersion {
|
||||||
fmt.Println(version.VERSION)
|
fmt.Println(version.VERSION)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("starting gonic %s\n", version.VERSION)
|
log.Printf("starting gonic %s\n", version.VERSION)
|
||||||
log.Printf("provided config\n")
|
log.Printf("provided config\n")
|
||||||
set.VisitAll(func(f *flag.Flag) {
|
set.VisitAll(func(f *flag.Flag) {
|
||||||
log.Printf(" %-15s %s\n", f.Name, f.Value)
|
log.Printf(" %-15s %s\n", f.Name, f.Value)
|
||||||
})
|
})
|
||||||
//
|
|
||||||
if _, err := os.Stat(*musicPath); os.IsNotExist(err) {
|
if _, err := os.Stat(*confMusicPath); os.IsNotExist(err) {
|
||||||
log.Fatal("please provide a valid music directory")
|
log.Fatal("please provide a valid music directory")
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(*cachePath); os.IsNotExist(err) {
|
if _, err := os.Stat(*confCachePath); os.IsNotExist(err) {
|
||||||
if err := os.MkdirAll(*cachePath, os.ModePerm); err != nil {
|
if err := os.MkdirAll(*confCachePath, os.ModePerm); err != nil {
|
||||||
log.Fatalf("couldn't create cache path: %v\n", err)
|
log.Fatalf("couldn't create cache path: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
coverCachePath := path.Join(*cachePath, coverCachePrefix)
|
coverCachePath := path.Join(*confCachePath, coverCachePrefix)
|
||||||
if _, err := os.Stat(coverCachePath); os.IsNotExist(err) {
|
if _, err := os.Stat(coverCachePath); os.IsNotExist(err) {
|
||||||
if err := os.MkdirAll(coverCachePath, os.ModePerm); err != nil {
|
if err := os.MkdirAll(coverCachePath, os.ModePerm); err != nil {
|
||||||
log.Fatalf("couldn't create cover cache path: %v\n", err)
|
log.Fatalf("couldn't create cover cache path: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db, err := db.New(*dbPath)
|
|
||||||
|
db, err := db.New(*confDBPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error opening database: %v\n", err)
|
log.Fatalf("error opening database: %v\n", err)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
//
|
|
||||||
proxyPrefixExpr := regexp.MustCompile(`^\/*(.*?)\/*$`)
|
proxyPrefixExpr := regexp.MustCompile(`^\/*(.*?)\/*$`)
|
||||||
*proxyPrefix = proxyPrefixExpr.ReplaceAllString(*proxyPrefix, `/$1`)
|
*confProxyPrefix = proxyPrefixExpr.ReplaceAllString(*confProxyPrefix, `/$1`)
|
||||||
//
|
|
||||||
server := server.New(server.Options{
|
server := server.New(server.Options{
|
||||||
DB: db,
|
DB: db,
|
||||||
MusicPath: *musicPath,
|
MusicPath: *confMusicPath,
|
||||||
CachePath: *cachePath,
|
CachePath: *confCachePath,
|
||||||
CoverCachePath: coverCachePath,
|
CoverCachePath: coverCachePath,
|
||||||
ProxyPrefix: *proxyPrefix,
|
ProxyPrefix: *confProxyPrefix,
|
||||||
})
|
})
|
||||||
|
|
||||||
var g run.Group
|
var g run.Group
|
||||||
g.Add(server.StartHTTP(*listenAddr))
|
g.Add(server.StartHTTP(*confListenAddr))
|
||||||
g.Add(server.StartSessionClean(cleanTimeDuration))
|
g.Add(server.StartSessionClean(cleanTimeDuration))
|
||||||
if *scanInterval > 0 {
|
if *confScanInterval > 0 {
|
||||||
tickerDur := time.Duration(*scanInterval) * time.Minute
|
tickerDur := time.Duration(*confScanInterval) * time.Minute
|
||||||
g.Add(server.StartScanTicker(tickerDur))
|
g.Add(server.StartScanTicker(tickerDur))
|
||||||
}
|
}
|
||||||
if *jukeboxEnabled {
|
if *confJukeboxEnabled {
|
||||||
g.Add(server.StartJukebox())
|
g.Add(server.StartJukebox())
|
||||||
}
|
}
|
||||||
if err := g.Run(); err != nil {
|
if err := g.Run(); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user