Skip to content

Commit

Permalink
Updated install and setup
Browse files Browse the repository at this point in the history
  • Loading branch information
lonelycode committed Mar 24, 2016
1 parent 51d561c commit 2ace7dd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 26 deletions.
21 changes: 18 additions & 3 deletions api_definition_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,19 @@ func (a *APIDefinitionLoader) readBody(response *http.Response) ([]byte, error)

}

func ReLogin() {
connStr := config.DBAppConfOptions.ConnectionString
if connStr == "" {
log.Fatal("Connection string is empty, failing.")
}

connStr = connStr + "/register/node"
log.WithFields(logrus.Fields{
"prefix": "main",
}).Info("Registering node.")
RegisterNodeWithDashboard(connStr, config.NodeSecret)
}

func RegisterNodeWithDashboard(endpoint string, secret string) error {
// Get the definitions
log.Debug("Calling: ", endpoint)
Expand Down Expand Up @@ -330,6 +343,7 @@ func SendHeartBeat(endpoint string, secret string) error {

newRequest.Header.Add("authorization", secret)
newRequest.Header.Add("x-tyk-nodeid", NodeID)
log.Debug("Sending Heartbeat as: ", NodeID)

ServiceNonceMutex.Lock()
newRequest.Header.Add("x-tyk-nonce", ServiceNonce)
Expand Down Expand Up @@ -426,6 +440,7 @@ func (a *APIDefinitionLoader) LoadDefinitionsFromDashboardService(endpoint strin
if decErr != nil {
log.Error("Failed to decode body: ", decErr)
log.Debug("Response was: ", string(retBody))
ReLogin()
return &APISpecs
}

Expand Down Expand Up @@ -526,9 +541,9 @@ func (a *APIDefinitionLoader) LoadDefinitionsFromRPC(orgId string) *[]*APISpec {

if config.SlaveOptions.BindToSlugsInsteadOfListenPaths {
newListenPath := "/" + thisAppConfig.Slug + "/"
log.Warning("Binding to ",
newListenPath,
" instead of ",
log.Warning("Binding to ",
newListenPath,
" instead of ",
thisAppConfig.Proxy.ListenPath)

thisAppConfig.Proxy.ListenPath = newListenPath
Expand Down
22 changes: 16 additions & 6 deletions install/data/tyk.with_dash.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"listen_port": LISTEN_PORT,
"node_secret": "352d20ee67be67f6340b4c0605b044b7",
"secret": "352d20ee67be67f6340b4c0605b044b7",
"template_path": "/opt/tyk-gateway/templates",
"tyk_js_path": "/opt/tyk-gateway/js/tyk.js",
"use_db_app_configs": true,
"db_app_conf_options": {
"connection_string": "DASHBOARD_URL",
"node_is_segmented": false,
"tags": []
},
"app_path": "/opt/tyk-gateway/apps",
"middleware_path": "/opt/tyk-gateway/middleware",
"storage": {
Expand All @@ -20,11 +26,14 @@
"analytics_config": {
"type": "mongo",
"csv_dir": "/tmp",
"mongo_url": "MONGO_URL",
"mongo_url": "",
"mongo_db_name": "",
"mongo_collection": "tyk_analytics",
"purge_delay": 5,
"ignored_ips": []
"mongo_collection": "",
"purge_delay": 100,
"ignored_ips": [],
"enable_detailed_recording": true,
"enable_geo_ip": false,
"geo_ip_db_path": ""
},
"health_check": {
"enable_health_checks": true,
Expand All @@ -33,9 +42,10 @@
"optimisations_use_async_session_write": true,
"allow_master_keys": false,
"policies": {
"policy_source": "mongo",
"policy_source": "service",
"policy_connection_string": "DASHBOARD_URL",
"policy_record_name": "tyk_policies"
},
},
"hash_keys": true,
"suppress_redis_signal_reload": false,
"close_connections": true,
Expand Down
31 changes: 14 additions & 17 deletions install/setup.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash
LISTEN_PORT=8080
USE_MONGO=""
USE_DASH=""
REDIS_PORT=6379
REDIS_HOST="localhost"
REDIS_PASSWORD=""
TYK_GATEWAY_DOMAIN="tyk.local"
MONGO_URL="mongodb://localhost/tyk_analytics"
DASHBOARD_URL="http://localhost:3000"

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

Expand All @@ -17,7 +17,8 @@ case $i in
shift # past argument=value
;;
-a=*|--dashboard=*)
USE_MONGO="${i#*=}"
USE_DASH="${i#*=}"
DASHBOARD_URL="${i#*=}"
shift # past argument=value
;;
-r=*|--redishost=*)
Expand All @@ -36,10 +37,6 @@ case $i in
TYK_GATEWAY_DOMAIN="${i#*=}"
shift # past argument=value
;;
-m=*|--mongo=*)
MONGO_URL="${i#*=}"
shift # past argument=value
;;
--default)
DEFAULT=YES
shift # past argument with no value
Expand All @@ -50,21 +47,21 @@ case $i in
esac
done

echo "Listen Port = ${LISTEN_PORT}"
echo "Redis Host = ${REDIS_HOST}"
echo "Redis Port = ${REDIS_PORT}"
echo "Redis PW = ${REDIS_PASSWORD}"
echo "Domain = ${TYK_GATEWAY_DOMAIN}"
echo "Listen Port = ${LISTEN_PORT}"
echo "Redis Host = ${REDIS_HOST}"
echo "Redis Port = ${REDIS_PORT}"
echo "Redis PW = ${REDIS_PASSWORD}"
echo "Domain = ${TYK_GATEWAY_DOMAIN}"

if [ -n "$USE_MONGO" ];
if [ -n "$USE_DASH" ];
then
echo "Use Mongo = ${USE_MONGO}"
echo "Mongo URL = ${MONGO_URL}"
echo "Use Pro = Yes"
echo "Dash URL = ${DASHBOARD_URL}"
fi

# Set up the editing file
TEMPLATE_FILE="tyk.self_contained.conf"
if [ -n "$USE_MONGO" ];
if [ -n "$USE_DASH" ];
then
echo "==> Setting up with Dashboard"
TEMPLATE_FILE="tyk.with_dash.conf"
Expand All @@ -77,7 +74,7 @@ sed -i 's/LISTEN_PORT/'$LISTEN_PORT'/g' $DIR/tyk.conf
sed -i 's/REDIS_HOST/'$REDIS_HOST'/g' $DIR/tyk.conf
sed -i 's/REDIS_PORT/'$REDIS_PORT'/g' $DIR/tyk.conf
sed -i 's/REDIS_PASSWORD/'$REDIS_PASSWORD'/g' $DIR/tyk.conf
sed -i 's#MONGO_URL#'$MONGO_URL'#g' $DIR/tyk.conf
sed -i 's#DASHBOARD_URL#'$DASHBOARD_URL'#g' $DIR/tyk.conf
sed -i 's#TYK_GATEWAY_DOMAIN#'$TYK_GATEWAY_DOMAIN'#g' $DIR/tyk.conf

echo "==> File written to ./tyk.conf"
Expand Down

0 comments on commit 2ace7dd

Please sign in to comment.