-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (66 loc) · 1.56 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"flag"
"github.com/boltdb/bolt"
"github.com/fsnotify/fsnotify"
"log"
"os"
"os/signal"
"syscall"
)
var (
logger, errorLog *log.Logger
db *bolt.DB
dbPath, configPath string
quickStart bool
watcher *fsnotify.Watcher
)
// Set up two loggers: logger for os.Stdout, and errorLog for error.log
func init() {
flag.StringVar(&dbPath, "database", "feeds.db", "path to BoltDB database")
flag.StringVar(&configPath, "config", "config.toml", "path to TOML config")
flag.BoolVar(&quickStart, "quick", false, "don't do an initial feed update")
flag.Parse()
logger = log.New(os.Stdout, "", log.LstdFlags|log.Lmicroseconds)
fp, err := os.Create("error.log")
if err != nil {
logger.Println(err)
}
errorLog = log.New(fp, "", log.LstdFlags|log.Lmicroseconds)
db, err = bolt.Open(dbPath, 0644, nil)
if err != nil {
logger.Fatalln(err)
}
watcher, err = fsnotify.NewWatcher()
if err != nil {
logger.Fatalln(err)
}
}
// cleanup closes the bolt database.
func cleanup() {
if err := watcher.Close(); err != nil {
logger.Printf("problem closing watcher: %v", err)
}
db.Close()
}
func main() {
logger.Println("starting up")
config, err := loadConfig(configPath)
if err != nil {
logger.Fatalln(err)
}
if err = watcher.Add(configPath); err != nil {
logger.Fatalln(err)
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
logger.Println("cleaning up")
cleanup()
logger.Println("shutting down")
os.Exit(1)
}()
rc := NewRiverContainer(config)
rc.Run()
}