Skip to content

Commit 782fb73

Browse files
committed
close
1 parent 77442b4 commit 782fb73

File tree

6 files changed

+53
-30
lines changed

6 files changed

+53
-30
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ rood ./config.json
5959
* Ping - GET http://localhost:6299/roo/v1/ping
6060
* Join a machine to the swarm - POST http://localhost:6299/roo/v1/join
6161
* Remove a machine from the swarm - POST http://localhost:6299/roo/v1/remove
62-
* Debug & Profiler Heap - GET http://localhost:6299/debug/pprof/heap
62+
* Debug Cmdline - GET http://localhost:6299/debug/pprof/heap
63+
* Debug Profile - GET http://localhost:6299/debug/pprof/profile
64+
* Debug Symbols - GET http://localhost:6299/debug/pprof/symbol
65+
* Debug Trace - GET http://localhost:6299/debug/pprof/trace
66+
* Debug Indices - GET http://localhost:6299/debug/pprof/1
6367

6468
## Getting Started (complete run-through example on Hetzner Cloud)
6569

roo/config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
"DefaultRedirect": "https://sfpl.io",
2121
"Debug": false,
2222
"AcmeStaging": false,
23+
"DataDirectoryRoot" : "",
2324
"Cluster": {
2425
"StartDelaySeconds": 0,
2526
"DNS": "localhost",
2627
"Resolver": "",
2728
"ReplicaID": 1,
2829
"ShardID": 1,
2930
"Binding" : "",
31+
"BootstrapHosts": true,
3032
"Service": {
3133
"Service": "kv",
3234
"Secure": true,
@@ -36,7 +38,8 @@
3638
"Key": "./.setup/keys/nginx.key",
3739
"Format": "json",
3840
"MessageLimit": 65536,
39-
"ByteLimit": 67108864
41+
"ByteLimit": 67108864,
42+
"Hosts" : []
4043
}
4144
},
4245
"X_Consume": [

roo/config.lan.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
"StartDelaySeconds": 0,
2525
"DNS": "localhost",
2626
"Resolver": "192.168.4.1",
27-
"ReplicaID": 2,
28-
"ShardID": 2,
27+
"ReplicaID": 1,
28+
"ShardID": 1,
2929
"Binding" : "192.168.4.200",
30+
"BootstrapHosts": false,
3031
"Service": {
3132
"Service": "kv",
3233
"Secure": true,
@@ -37,7 +38,7 @@
3738
"Format": "json",
3839
"MessageLimit": 65536,
3940
"ByteLimit": 67108864,
40-
"Hosts": ["192.168.4.178"]
41+
"Hosts": []
4142
}
4243
},
4344
"X_Consume": [

roo/kv.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ import (
6262
"os/signal"
6363
"path/filepath"
6464
"runtime"
65-
"sort"
6665
"strconv"
6766
"syscall"
6867
"time"
@@ -106,7 +105,7 @@ func (kvs *KvService) connect() error {
106105
}
107106

108107
//Now exclude IPs from the hosts (ours or other IPv6)
109-
tmp := kvs.Configuration.Hosts[:0]
108+
tmp := make([]string, 0)
110109
for i := 0; i < len(kvs.Configuration.Hosts); i++ {
111110
if kvs.Configuration.Hosts[i] != kvs.AppConfig.Cluster.Binding && net.ParseIP(kvs.Configuration.Hosts[i]) != nil && net.ParseIP(kvs.Configuration.Hosts[i]).To4() != nil {
112111
tmp = append(tmp, kvs.Configuration.Hosts[i])
@@ -132,8 +131,11 @@ func (kvs *KvService) connect() error {
132131
SnapshotEntries: 10,
133132
CompactionOverhead: 5,
134133
}
134+
if kvs.AppConfig.DataDirectoryRoot == "" {
135+
kvs.AppConfig.DataDirectoryRoot = "cluster-data"
136+
}
135137
datadir := filepath.Join(
136-
"cluster-data",
138+
kvs.AppConfig.DataDirectoryRoot,
137139
"roo",
138140
fmt.Sprintf("node%d", kvs.AppConfig.Cluster.ReplicaID))
139141

@@ -160,8 +162,8 @@ func (kvs *KvService) connect() error {
160162
olderThan = 0
161163
for _, h := range kvs.Configuration.Hosts {
162164
fmt.Println(h)
163-
if sort.Search(len(myIPstrings), func(i int) bool { return myIPstrings[i] == h }) > 0 ||
164-
h == kvs.AppConfig.Cluster.Binding ||
165+
if h == kvs.AppConfig.Cluster.Binding ||
166+
//sort.Search(len(myIPstrings), func(i int) bool { return myIPstrings[i] == h }) > 0 ||
165167
net.ParseIP(h).To4() == nil {
166168
continue
167169
}

roo/roo.go

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,29 @@ func main() {
161161
////////////////////////////////////////DNS QUERY
162162
rlog.Infof("Cluster: Looking up hosts at: %s\n", configuration.Cluster.DNS)
163163
tmpHosts := make([]string, 0)
164-
if configuration.Cluster.Resolver == "" {
165-
rlog.Infof("Cluster: DNS Resolver: Using the OS default\n")
166-
tmpHosts, _ = net.LookupHost(configuration.Cluster.DNS)
167-
} else {
168-
r := &net.Resolver{
169-
PreferGo: false,
170-
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
171-
d := net.Dialer{
172-
Timeout: time.Millisecond * time.Duration(10000),
173-
}
174-
return d.DialContext(ctx, "udp", configuration.Cluster.Resolver+":53")
175-
},
176-
}
177-
rlog.Infof("Cluster: DNS Resolver: %s\n", configuration.Cluster.Resolver)
178-
var err error
179-
if tmpHosts, err = r.LookupHost(context.Background(), configuration.Cluster.DNS); err != nil {
180-
log.Fatalf("[CRITICAL] Cluster: DNS Resolver failed %v", err)
164+
if configuration.Cluster.BootstrapHosts {
165+
rlog.Infof("Cluster: Bootstrapping Hosts\n")
166+
if configuration.Cluster.Resolver == "" {
167+
rlog.Infof("Cluster: DNS Resolver: Using the OS default\n")
168+
tmpHosts, _ = net.LookupHost(configuration.Cluster.DNS)
169+
} else {
170+
r := &net.Resolver{
171+
PreferGo: false,
172+
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
173+
d := net.Dialer{
174+
Timeout: time.Millisecond * time.Duration(10000),
175+
}
176+
return d.DialContext(ctx, "udp", configuration.Cluster.Resolver+":53")
177+
},
178+
}
179+
rlog.Infof("Cluster: DNS Resolver: %s\n", configuration.Cluster.Resolver)
180+
var err error
181+
if tmpHosts, err = r.LookupHost(context.Background(), configuration.Cluster.DNS); err != nil {
182+
log.Fatalf("[CRITICAL] Cluster: DNS Resolver failed %v", err)
183+
}
181184
}
182185
}
186+
183187
configuration.Cluster.Service.Hosts = append(configuration.Cluster.Service.Hosts, tmpHosts...)
184188
rlog.Infof("Cluster: Possible Roo Peer IPs: %s\n", configuration.Cluster.Service.Hosts)
185189

@@ -376,7 +380,14 @@ func main() {
376380
//////////////////////////////////////// SETUP API - INTERNAL NETWORK PORT :6299 (default) AS NOT EXPOSED
377381
//TODO: ADD SSL SUPPORT
378382
//rtrm := http.TimeoutHandler(rtr, time.Second*60, "") //Can stack these
379-
go http.ListenAndServe(API_PORT, rtr)
383+
if configuration.Cluster.Binding != "" {
384+
endpoint := configuration.Cluster.Binding + API_PORT
385+
rlog.Infof("API: Listening on %s", endpoint)
386+
go http.ListenAndServe(endpoint, rtr)
387+
} else {
388+
rlog.Infof("API: Listening on *ALL* local endpoints")
389+
go http.ListenAndServe(API_PORT, rtr)
390+
}
380391

381392
//////////////////////////////////////// LOAD CLUSTER
382393
{
@@ -551,7 +562,7 @@ func main() {
551562
},
552563
}
553564
server := &http.Server{ // HTTP REDIR SSL RENEW
554-
Addr: ":https",
565+
Addr: configuration.Cluster.Binding + ":9999",
555566
ReadTimeout: time.Duration(configuration.ReadTimeoutSeconds) * time.Second,
556567
ReadHeaderTimeout: time.Duration(configuration.ReadHeaderTimeoutSeconds) * time.Second,
557568
WriteTimeout: time.Duration(configuration.WriteTimeoutSeconds) * time.Second,
@@ -603,7 +614,7 @@ func main() {
603614
//////////////////////////////////////// ACTUALLY RUN THE SERVICES
604615
//TODO: Wait to start until nh is created from raft cluster
605616
//Redirect HTTP->HTTPS
606-
go http.ListenAndServe(":http", certManager.HTTPHandler(nil))
617+
go http.ListenAndServe(configuration.Cluster.Binding+":http", certManager.HTTPHandler(nil))
607618

608619
//Start the actual Proxy Service
609620
log.Fatal(server.ListenAndServeTLS("", ""))

roo/typedefs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ type Cluster struct {
116116
Service *Service
117117
DNS string
118118
Resolver string
119+
BootstrapHosts bool
119120
Binding string
120121
ReplicaID uint64
121122
ShardID uint64
@@ -141,6 +142,7 @@ type Configuration struct {
141142
SchemaVersion int
142143
ApiVersion int
143144
ApiVersionString string
145+
DataDirectoryRoot string
144146
AcmeStaging bool
145147
Test bool
146148
Swarm bool

0 commit comments

Comments
 (0)