forked from lightninglabs/pool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
50 lines (43 loc) · 1.11 KB
/
run.go
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
package pool
import (
"fmt"
"os"
"path/filepath"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/signal"
)
// Run starts the trader daemon and blocks until it's shut down again.
func Run(cfg *Config) error {
// Hook interceptor for os signals.
shutdownInterceptor, err := signal.Intercept()
if err != nil {
return err
}
logWriter := build.NewRotatingLogWriter()
SetupLoggers(logWriter, shutdownInterceptor)
// Special show command to list supported subsystems and exit.
if cfg.DebugLevel == "show" {
fmt.Printf("Supported subsystems: %v\n",
logWriter.SupportedSubsystems())
os.Exit(0)
}
// Initialize logging at the default logging level.
err = logWriter.InitLogRotator(
filepath.Join(cfg.LogDir, DefaultLogFilename),
cfg.MaxLogFileSize, cfg.MaxLogFiles,
)
if err != nil {
return err
}
err = build.ParseAndSetDebugLevels(cfg.DebugLevel, logWriter)
if err != nil {
return err
}
trader := NewServer(cfg)
err = trader.Start()
if err != nil {
return fmt.Errorf("unable to start server: %v", err)
}
<-shutdownInterceptor.ShutdownChannel()
return trader.Stop()
}