-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
147 lines (143 loc) · 5.36 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// -*- mode: go; tab-width: 2; indent-tabs-mode: 1; st-rulers: [70] -*-
// vim: ts=4 sw=4 ft=lua noet
//--------------------------------------------------------------------
// @author Daniel Barney <[email protected]>
// @author Greg Linton <[email protected]>
// @copyright 2016, Pagoda Box Inc.
// @doc
//
// @end
// Created : 7 August 2015 by Daniel Barney <[email protected]>
// Refactored : March 2016 by Greg Linton <[email protected]>
//--------------------------------------------------------------------
// Portal is an api-driven, in-kernel layer 2/3 load balancer with
// http/s proxy cababilities.
//
// Usage
//
// To run as a server, using the defaults, starting portal is as simple as
// portal -s
// For more specific usage information, refer to the help doc (portal -h):
//
// Usage:
// portal [flags]
// portal [command]
//
// Available Commands:
// add-service Add service
// remove-service Remove service
// show-service Show service
// show-services Show all services
// set-services Set service list
// set-service Set service
// add-server Add server to a service
// remove-server Remove server from a service
// show-server Show server on a service
// show-servers Show all servers on a service
// set-servers Set server list on a service
// add-route Add route
// set-routes Set route list
// show-routes Show all routes
// remove-route Remove route
// add-cert Add cert
// set-certs Set cert list
// show-certs Show all certs
// remove-cert Remove cert
//
// Flags:
// -C, --api-cert="": SSL cert for the api
// -H, --api-host="127.0.0.1": Listen address for the API
// -k, --api-key="": SSL key for the api
// -p, --api-key-password="": Password for the SSL key
// -P, --api-port="8443": Listen address for the API
// -t, --api-token="": Token for API Access
// -b, --balancer="lvs": Load balancer to use (nginx|lvs)
// -r, --cluster-connection="none://": Cluster connection string (redis://127.0.0.1:6379)
// -T, --cluster-token="": Cluster security token
// -c, --conf="": Configuration file to load
// -d, --db-connection="scribble:///var/db/portal": Database connection string
// -i, --insecure[=false]: Disable tls key checking (client) and listen on http (server)
// -j, --just-proxy[=false]: Proxy only (no tcp/udp load balancing)
// -L, --log-file="": Log file to write to
// -l, --log-level="INFO": Log level to output
// -x, --proxy-http="0.0.0.0:80": Address to listen on for proxying http
// -X, --proxy-tls="0.0.0.0:443": Address to listen on for proxying https
// -s, --server[=false]: Run in server mode
// -v, --version[=false]: Print version info and exit
// -w, --work-dir="/var/db/portal": Directory for portal to use (balancer config)
//
// Use "portal [command] --help" for more information about a command.
//
//
// Build Specs
//
// It is built with clustering at it's core
// to ensure syncronization between nodes. It utilizes a multi-master
// replication system allowing any node to accept requests to update
// load balancing or proxy rules. The high-level workflow is as follows:
//
// // every call starts by hitting the api
// API - setRoute
// - calls cluster.SetRoute
//
// // in order to ensure syncronization comes first, cluster starts the work
// CLUSTER - SetRoute
// - calls publish "set-route"
//
// // the redis clusterer utilizes the pub/sub functionality for syncronization
// // when it recieves a message, it calls on "common" to implement the changes
// SUBSCRIBER - on "set-route"
// - calls common.SetRoute
//
// // common contains all the logic to perform an action, as well as roll back
// // other "systems" upon failure, effectively "undoing" the action
// COMMON - SetRoute
// - calls proxymgr.SetRoute & database.SetRoute
// - rolls back proxymgr if database fails
//
// SUBSCRIBER
// - if common.SetRoute was successful, write success to redis for self, otherwise
// rollback self
//
// // the cluster member that received the request ensures all members got the update
// CLUSTER
// - returns err if not all members have set route
// - rolls back `common` (via publish) if not all members can set route
//
// API
// - if error, return 500 response, otherwise respond as fits
//
// Portal is also extremely "pluggable", meaning that it is easy to code in
// another tool to be a "Balancer" or "Proxy" by matching the interfaces.
// Individual object (database|balancer|proxy) functions are never called
// directly by "common". "Common" calls package level functions such as
// database.SetService
// which calls/sreturns the selected "Backend's" SetService function.
// The type of backend (scribble/redis) is determined from the connection
// configuration option, as seen in the package's Init() function:
// url, err := url.Parse(config.ClusterConnection)
// if err != nil {
// return fmt.Errorf("Failed to parse db connection - %s", err)
// }
//
// switch url.Scheme {
// case "redis":
// Clusterer = &Redis{}
// case "none":
// Clusterer = &None{}
// default:
// Clusterer = &None{}
// }
//
// return Clusterer.Init()
package main
import (
"fmt"
"github.com/nanopack/portal/commands"
)
func main() {
err := commands.Portal.Execute()
if err != nil && err.Error() != "" {
fmt.Println(err)
}
}