-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.go
77 lines (60 loc) · 1.35 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
package main
import (
"fmt"
"log"
"sync"
"github.com/GitJournal/git-auto-sync/common"
cfg "github.com/GitJournal/git-auto-sync/common/config"
"github.com/kardianos/service"
)
type Daemon struct{}
func (d *Daemon) Start(s service.Service) error {
go d.run()
return nil
}
func (d *Daemon) run() {
config, err := cfg.Read()
if err != nil {
panic(err)
}
var wg sync.WaitGroup
for _, repoPath := range config.Repos {
wg.Add(1)
fmt.Println("Monitoring", repoPath)
go watchForChanges(&wg, repoPath)
}
wg.Wait()
}
func (d *Daemon) Stop(s service.Service) error {
// Stop should not block. Return with a few seconds.
return nil
}
func main() {
daemon := Daemon{}
autoSyncService, err := common.NewServiceWithDaemon(&daemon)
if err != nil {
log.Fatal("BuildService", err)
}
s := autoSyncService.Service
logger, err := s.Logger(nil)
if err != nil {
log.Fatal("BuildLogger", err)
}
err = s.Run()
if err != nil {
_ = logger.Error("RunService", err)
}
}
// FIXME: pass some kind of channel which tells this when to close!
func watchForChanges(wg *sync.WaitGroup, repoPath string) {
defer wg.Done()
cfg, err := common.NewRepoConfig(repoPath)
if err != nil {
log.Println(err)
}
err = common.WatchForChanges(cfg)
if err != nil {
log.Println(err)
}
}
// FIXME: Handle operating system signal which tells it to reload the config