-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
150 lines (141 loc) · 3.55 KB
/
start.sh
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
148
149
150
#!/bin/sh
set -e
#set -x
func_init(){
func_check_env
}
func_set_service_nodes(){
mm=`echo $DEPEND_SERVICE | sed "s/,/ /g"`
SERVICE_NODE=""
if [[ "$PLUGIN_MOEL" == "net-plugin:up" ]];then
echo "set service_node with service_name"
SERVICE_NODE=$SERVICE_NAME
fi
for nn in $mm
do
ALIAS=`echo $nn | awk -F ":" '{print $1}'`
if [[ "$SERVICE_NODE" == "" ]];then
SERVICE_NODE=$ALIAS
continue
fi
SERVICE_NODE=$SERVICE_NODE"_"$ALIAS
done
echo "service node is $SERVICE_NODE"
echo "plugin id is $PLUGIN_ID"
echo "plugin model is $PLUGIN_MOEL"
}
func_modify_conf(){
cat <<EOF>> $CONFIGPATH
{
"listeners": [],
"lds": {
"cluster": "lds",
"refresh_delay_ms": 3000
},
"admin": {
"access_log_path": "/dev/null",
"address": "tcp://0.0.0.0:65534"
},
"cluster_manager": {
"sds": {
"cluster": {
"name": "sds",
"connect_timeout_ms": 250,
"type": "strict_dns",
"lb_type": "round_robin",
"hosts": [
{
"url": "tcp://${DISCOVERSERVER}:${DISCOVERPORT}"
}
]
},
"refresh_delay_ms": 3000
},
"cds": {
"cluster": {
"name": "cds",
"connect_timeout_ms": 250,
"type": "strict_dns",
"lb_type": "round_robin",
"hosts": [
{
"url": "tcp://${DISCOVERSERVER}:${DISCOVERPORT}"
}
]
},
"refresh_delay_ms": 3000
},
"clusters": [
{
"name": "lds",
"connect_timeout_ms": 250,
"type": "strict_dns",
"lb_type": "round_robin",
"hosts": [
{
"url": "tcp://${DISCOVERSERVER}:${DISCOVERPORT}"
}
]
}
]
}
}
EOF
}
func_update_conf(){
sed -i 's/DISCOVERSERVER/${DISCOVERSERVER}/g' $CONFIGPATH
if [[ $? != 0 ]];then
exit 8
fi
sed -i 's/DISCOVERPORT/$DISCOVERPORT/g' $CONFIGPATH
if [[ $? != 0 ]];then
exit 8
fi
}
func_main(){
func_init
func_set_service_nodes
func_modify_conf
$ENVOY_BINARY -c $CONFIGPATH --service-cluster $TENANT_ID"_"$PLUGIN_ID"_"$SERVICE_NAME --service-node $SERVICE_NODE
}
func_check_env(){
#@ DISCOVERSERVER DISCOVERPORT TENANT_ID DEPEND_SERVICE
if [[ -z $DISCOVER_URL ]];then
export DISCOVER_URL="http://172.30.42.1:6100/"
fi
DISCOVERSERVER=`echo $DISCOVER_URL | awk -F "/" '{print $3}' | awk -F ":" '{print $1}'`
DISCOVERPORT=`echo $DISCOVER_URL | awk -F "/" '{print $3}' | awk -F ":" '{print $2}'`
if [[ -z $DISCOVERSERVER ]];then
DISCOVERSERVER="127.0.0.1"
echo "env DISCOVERSERVER set to default localhost."
fi
if [[ -z $DISCOVERPORT ]];then
DISCOVERPORT=6100
echo "env DISCOVERPORT set to default 6100"
fi
if [[ -z $CONFIGPATH ]];then
CONFIGPATH="/root/envoy_config.json"
fi
if [[ -z $ENVOY_BINARY ]];then
ENVOY_BINARY="/usr/local/bin/envoy"
fi
if [[ -z $TENANT_ID ]];then
echo "need env TENANT_ID"
exit 9
fi
if [[ -z $PLUGIN_ID ]];then
echo "need env PLUGIN_ID"
exit 9
fi
}
func_test(){
export DEPEND_SERVICE=gr6adef3:9a1576b6a4a8e3185646cdae916adef3,gr123123:678906781923123sdfssdfsgsgs,gr44444:adsfadfafadfasdfasdfasdf
#DEPEND_SERVICE=gr6adef3:9a1576b6a4a8e3185646cdae916adef3
export TENANT_ID=1b05123123124tenantid
export SERVICE_NAME=grtest12
export PLUGIN_ID=envoy123123123123
}
if [[ "$1" == "test" ]];then
func_test
fi
func_main