-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
79 lines (71 loc) · 1.64 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 (
"fmt"
"io"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/sirupsen/logrus"
)
var (
logger *logrus.Logger
)
func main() {
syscall.Umask(0) // file mode perms
// Logger
logFile, _ := os.OpenFile("debug.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
eventFile, err := os.OpenFile("events.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
log.Fatal(err)
}
logger = logrus.New()
logger.SetFormatter(&logrus.JSONFormatter{})
logger.SetOutput(eventFile)
mw := io.MultiWriter(os.Stdout, logFile)
log.SetOutput(mw)
// Start log file rotation
go monitorFileSize()
// Command line arguments and flags
ParseFlags()
// Activate Clustering
InitMyNode()
if *ClusterMode {
BeginClustering()
}
// Apps
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
// next 2 lines temp for noise testing
// <-c
// os.Exit(1)
initApp("Example App") // For testing
go func() {
// cluster := initCluster()
CheckDocumentsFolder()
LoadAppsFromDisk()
for _, app := range Apps {
start := time.Now()
app.LoadIndexesFromDisk()
end := time.Now()
fmt.Println("Load index time", end.Sub(start))
log.Println("starting webservers...")
StartWebserver(app) // FIXME: HOLY SHIT THIS IS DUMB, need to update to pass app name in url
}
}()
<-c
if *FellowNodes != "" {
log.Println("### Leaving Gossip")
LeaveGossipCluster()
}
log.Println("### Serializing apps and indexes before exiting...")
for _, app := range Apps {
start := time.Now()
app.SerializeIndex()
end := time.Now()
fmt.Println("Serialize index time", end.Sub(start))
app.SerializeApp()
}
os.Exit(1)
}