forked from sirrobot01/decypharr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
71 lines (58 loc) · 1.81 KB
/
Copy pathmain.go
File metadata and controls
71 lines (58 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"flag"
"log"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"runtime/debug"
"syscall"
"github.com/sirrobot01/decypharr/internal/config"
"github.com/sirrobot01/decypharr/cmd/decypharr"
)
func main() {
defer func() {
if r := recover(); r != nil {
log.Printf("FATAL: Recovered from panic in main: %v\n", r)
debug.PrintStack()
}
}()
// Subcommands are dispatched before flag parsing, which would otherwise
// stop at the subcommand name and treat it as a positional argument.
if len(os.Args) > 1 && os.Args[1] == downgradeCommand {
if err := runDowngrade(os.Args[2:]); err != nil {
log.Fatalf("%s: %v", downgradeCommand, err)
}
return
}
var configPath string
var pprofAddr string
// Create a default config directory if it doesn't exist
flag.StringVar(&configPath, "config", "", "path to the data folder")
flag.StringVar(&pprofAddr, "pprof", ":6060", "pprof server address (set to empty to disable)")
flag.Parse()
// get enable pprof flag from environment variable if not set via flag
enablePprof := os.Getenv("ENABLE_PPROF") != ""
config.SetConfigPath(resolveConfigPath(configPath))
config.Get()
// Buffer pools are owned by their subsystems: the DFS cache (vfs.NewCache)
// and the usenet reader each create a buffer.Pool with their own configured
// RAM budget and disk limit.
// Start pprof server if enabled
if pprofAddr != "" && enablePprof {
go func() {
log.Printf("Starting pprof server on %s", pprofAddr)
if err := http.ListenAndServe(pprofAddr, nil); err != nil {
log.Printf("pprof server error: %v", err)
}
}()
}
// Create a context canceled on SIGINT/SIGTERM
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
if err := decypharr.Start(ctx); err != nil {
log.Fatal(err)
}
}