This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
80 lines (70 loc) · 1.79 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
80
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"net"
"net/http"
"net/rpc"
"time"
)
// TODO the rest
var serverRoot = flag.String("serverRoot", "", "Path to the root directory in the prod machine")
var port = flag.Int("port", 8000, "port to serve on / connect to")
var serverMode = flag.Bool("server", false, "If true, run as a server.")
var runBackgroundCheck = flag.Bool("enforce", false, "Run background enforcer")
var deployFile = flag.String("cfg", "deploy.json", "Deploy config file")
var targetName = flag.String("target", "prod", "Target backend")
var isLocalTest = flag.Bool("is-local-test", false, "Don't use ssh, and connect to a camus server running locally")
func main() {
// seed random number generator
t := time.Now().UTC()
rand.Seed(t.UnixNano())
welcome()
flag.Parse()
if *serverMode {
serverMain()
} else {
clientMain()
}
}
func serverMain() {
server, err := NewServerImpl(
*serverRoot,
*runBackgroundCheck,
*port)
if err != nil {
log.Fatal("NewServer:", err)
}
rpcServer := &RpcServer{server}
rpc.Register(rpcServer)
rpc.HandleHTTP()
// Localhost only, in case it's not behind a firewall!
portStr := fmt.Sprintf("localhost:%d", *port)
l, err := net.Listen("tcp", portStr)
if err != nil {
log.Fatal("failed to listen:", err)
}
fmt.Printf("Listening on %s\n", portStr)
http.Serve(l, nil)
}
func clientMain() {
client, err := NewClient(*deployFile, TargetName(*targetName), *isLocalTest)
if err != nil {
log.Fatal("NewClient:", err)
}
err = NewTerminalClient(flag.CommandLine, client).Run()
if err != nil {
log.Fatal(err)
}
}
func welcome() {
println()
println(" " + QUOTES[time.Now().UnixNano()%int64(len(QUOTES))])
println(" -- Camus")
println()
}
func sleepSeconds(seconds int) {
time.Sleep(time.Duration(seconds) * time.Second)
}