forked from apache/inlong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinlong-daemon
230 lines (211 loc) · 6.35 KB
/
inlong-daemon
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# globle values
INLONG_HOME=$(
cd $(dirname $0)
cd ..
pwd
)
source $INLONG_HOME/conf/inlong.conf
command_help() {
echo "Usage: ./inlong-daemon (start|stop) <command>
where command is one of:
audit Run a Audit Service
manager Run a Manager Service
dashboard Run a Dashboard Service
dataproxy Run a Dataproxy Service
agent Run a Agent Service
standalone Run a Standalone mode(All Service)"
}
# wait the service to start
wait_port_to_listen() {
service_name=$1
service_port=$2
result=$(lsof -Pi :${service_port} -sTCP:LISTEN)
while [[ -z "$result" ]]; do
echo "waiting $service_name to start, sleep 3s ..."
sleep 3
result=$(lsof -Pi :${service_port} -sTCP:LISTEN)
done
}
# if less than two arguments supplied
if [ $# -lt 2 ]; then
command_help
exit 1
fi
COMMAND=$1
SERVICE=$2
init_compo() {
if [[ "$SERVICE" != standalone ]]; then
cd $INLONG_HOME/bin
echo "init $SERVICE"
bash +x ./init-config.sh $SERVICE
fi
}
start_inlong_audit() {
init_compo
echo "init apache_inlong_audit"
cd $INLONG_HOME/inlong-audit
select_db_sql="SELECT COUNT(*) FROM information_schema.TABLES WHERE table_schema = 'apache_inlong_audit'"
inlong_audit_count=$(mysql -h${spring_datasource_hostname} -P${spring_datasource_port} -u${spring_datasource_username} -p${spring_datasource_password} -e "${select_db_sql}")
inlong_num=$(echo $inlong_audit_count | tr -cd "[0-9]")
if [ $inlong_num -eq 0 ]; then
mysql -h${spring_datasource_hostname} -P${spring_datasource_port} -u${spring_datasource_username} -p${spring_datasource_password} <sql/apache_inlong_audit.sql
fi
echo "start audit proxy"
if [ $mq_type == "pulsar" ]; then
bash +x ./bin/proxy-start.sh pulsar
fi
if [ $mq_type == "tubemq" ]; then
bash +x ./bin/proxy-start.sh tube
fi
echo "start audit store"
bash +x ./bin/store-start.sh
# wait to start
wait_port_to_listen audit ${audit_proxys_port}
}
start_inlong_manager() {
init_compo
echo "start manager"
cd $INLONG_HOME/inlong-manager
# Whether the database table exists. If it does not exist, initialize the database and skip if it exists.
select_db_sql="SELECT COUNT(*) FROM information_schema.TABLES WHERE table_schema = 'apache_inlong_manager'"
inlong_manager_count=$(mysql -h${spring_datasource_hostname} -P${spring_datasource_port} -u${spring_datasource_username} -p${spring_datasource_password} -e "${select_db_sql}")
inlong_num=$(echo $inlong_manager_count | tr -cd "[0-9]")
if [ $inlong_num -eq 0 ]; then
echo "init apache_inlong_manager database"
mysql -h${spring_datasource_hostname} -P${spring_datasource_port} -u${spring_datasource_username} -p${spring_datasource_password} <sql/apache_inlong_manager.sql
fi
bash +x ./bin/startup.sh
# wait to start
wait_port_to_listen manager ${manager_server_port}
}
start_inlong_dashboard() {
echo "start dashboard"
if [[ "$manager_server_hostname" == "localhost" || "$manager_server_hostname" == "127.0.0.1" ]]; then
manager_server_hostname=$local_ip
fi
docker run -d --name dashboard -e MANAGER_API_ADDRESS=${local_ip}:${manager_server_port} -p ${dashboard_mapping_port}:80 ${dashboard_docker_image}
}
start_inlong_dataproxy() {
init_compo
echo "start dataproxy"
cd $INLONG_HOME/inlong-dataproxy
if [ $mq_type == "pulsar" ]; then
bash +x ./bin/dataproxy-start.sh pulsar
fi
if [ $mq_type == "tubemq" ]; then
bash +x ./bin/dataproxy-start.sh tube
fi
# wait to start
wait_port_to_listen dataproxy ${dataproxy_port}
}
start_inlong_agent() {
init_compo
echo "start agent"
cd $INLONG_HOME/inlong-agent
bash +x ./bin/agent.sh start
# wait to start
wait_port_to_listen agent ${agent_port}
}
# register dataproxy for standalone
register_service() {
curl --header "Content-Type: application/json" --request POST http://${manager_server_hostname}:${manager_server_port}/api/inlong/manager/openapi/cluster/save --data '
{
"name": "default_dataproxy",
"type": "DATA_PROXY",
"ip": "127.0.0.7",
"port": 46801,
"mqSetName": "default_set_name",
"inCharges": "admin",
"creator": "admin"
}
'
}
# start inlong
start_inlong_all() {
echo "init configuration"
cd $INLONG_HOME/bin
bash +x ./init-config.sh
# start inlong manager
start_inlong_manager
# start inlong audit
start_inlong_audit
# start inlong dashboard
start_inlong_dashboard
# start inlong dataproxy
start_inlong_dataproxy
register_service
# start inlong agent
start_inlong_agent
}
stop_inlong_manager() {
echo "stop manager"
cd $INLONG_HOME/inlong-manager/bin
bash +x ./shutdown.sh
}
stop_inlong_dashboard() {
docker stop dashboard
docker rm dashboard
}
stop_inlong_dataproxy() {
echo "stop dataproxy"
cd $INLONG_HOME/inlong-dataproxy/bin
bash +x ./dataproxy-stop.sh
}
stop_inlong_audit() {
echo "stop audit"
cd $INLONG_HOME/inlong-audit/bin
bash +x ./proxy-stop.sh
bash +x ./store-stop.sh
}
stop_inlong_agent() {
echo "stop agent"
cd $INLONG_HOME/inlong-agent/bin
bash +x ./agent.sh stop
}
# stop inlong
stop_inlong_all() {
# stop inlong dashboard
stop_inlong_dashboard
# stop inlong dataproxy
stop_inlong_dataproxy
# stop inlong agent
stop_inlong_agent
# stop inlong audit
stop_inlong_audit
# stop inlong manager
stop_inlong_manager
}
if [[ "$COMMAND" == start || "$COMMAND" == stop ]]; then
case $SERVICE in
manager | dashboard | dataproxy | agent | audit)
${COMMAND}_inlong_${SERVICE}
;;
standalone)
${COMMAND}_inlong_all
;;
*)
command_help
exit 1
;;
esac
else
command_help
exit 1
fi