-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto.go
55 lines (51 loc) · 1.57 KB
/
proto.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
// Memstore prototype
// (c) 2023 Laurent Demailly - all rights reserved
// Apache 2.0 License
package main
import (
"flag"
"os"
"fortio.org/dflag"
"fortio.org/fortio/fhttp"
"fortio.org/log"
"fortio.org/memstore/mstore"
"fortio.org/memstore/probes"
"fortio.org/scli"
)
func main() {
port := flag.String("port", "8080", "Port to listen on")
dflag.Flag("peers", mstore.Peers)
dflag.Flag("dns", mstore.DNSWatch)
dflag.Flag("dns-interval", mstore.DNSWatchSleepTime)
dflag.FlagBool("statefulset", mstore.StatefulSet)
dflag.FlagBool("ready", probes.ReadyFlag)
scli.ServerMain()
if mstore.StatefulSet.Get() && mstore.DNSWatch.Get() == "" {
log.Fatalf("StatefulSet mode needs -dns to be set")
}
if mstore.DNSWatch.Get() != "" && mstore.Peers.Get().Len() > 0 {
log.Fatalf("Can only have either -peers or -dns set, not both")
}
myName, found := os.LookupEnv("NAME")
if mstore.StatefulSet.Get() && !found {
log.Fatalf("No NAME env var found for statefulset mode (to this pod's name)")
}
epoch := os.Getenv("EPOCH")
log.Infof("Starting memstore with name %q and epoch %s", myName, epoch)
mstore.Start(myName)
mux, addr := fhttp.HTTPServer("memstore", *port)
if addr == nil {
log.Fatalf("Failed to start http server")
}
probes.Setup(mux)
probes.State.SetLive(true)
probes.State.SetStarted(true)
// For testing/changing we can use curl to set flags podip:7999/set?name=ready&value=true
/*
time.Sleep(50 * time.Second) // give time for the probes to be ready
log.Warnf("Switching back to not ready")
probes.State.SetReady(false)
*/
scli.UntilInterrupted()
mstore.Stop()
}