Files
open-im-server/script/start_rpc_service.sh
T

81 lines
2.2 KiB
Bash
Raw Normal View History

2021-05-26 19:27:41 +08:00
#!/usr/bin/env bash
source ./style_info.cfg
source ./path_info.cfg
source ./function.sh
#service filename
service_filename=(
#api
open_im_api
#rpc
open_im_user
open_im_friend
open_im_group
open_im_auth
${msg_name}
2022-04-24 11:23:54 +08:00
open_im_conversation
2021-05-26 19:27:41 +08:00
)
#service config port name
service_port_name=(
#api port name
openImApiPort
#rpc port name
openImUserPort
openImFriendPort
openImGroupPort
2022-02-23 09:49:02 +08:00
openImAuthPort
2022-04-24 17:54:02 +08:00
openImMessagePort
2022-04-24 11:23:54 +08:00
openImConversationPort
2021-05-26 19:27:41 +08:00
)
2022-09-12 19:32:24 +08:00
service_prometheus_port_name=(
#api port name
openImApiPort
#rpc port name
userPrometheusPort
friendPrometheusPort
groupPrometheusPort
authPrometheusPort
messagePrometheusPort
conversationPrometheusPort
)
2021-05-26 19:27:41 +08:00
for ((i = 0; i < ${#service_filename[*]}; i++)); do
#Check whether the service exists
service_name="ps -aux |grep -w ${service_filename[$i]} |grep -v grep"
count="${service_name}| wc -l"
if [ $(eval ${count}) -gt 0 ]; then
pid="${service_name}| awk '{print \$2}'"
2022-04-06 11:47:01 +08:00
echo "${service_filename[$i]} service has been started,pid:$(eval $pid)"
echo "killing the service ${service_filename[$i]} pid:$(eval $pid)"
2021-05-26 19:27:41 +08:00
#kill the service that existed
kill -9 $(eval $pid)
sleep 0.5
fi
2022-04-06 11:47:01 +08:00
cd ../bin
2021-05-26 19:27:41 +08:00
#Get the rpc port in the configuration file
portList=$(cat $config_path | grep ${service_port_name[$i]} | awk -F '[:]' '{print $NF}')
list_to_string ${portList}
2022-09-12 19:32:24 +08:00
service_ports=($ports_array)
2022-09-12 20:11:33 +08:00
portList2=$(cat $config_path | grep ${service_prometheus_port_name[$i]} | awk -F '[:]' '{print $NF}')
2022-09-12 19:32:24 +08:00
list_to_string $portList2
prome_ports=($ports_array)
2021-05-26 19:27:41 +08:00
#Start related rpc services based on the number of ports
2022-09-12 23:38:34 +08:00
for ((j = 0; j < ${#service_ports[*]}; j++)); do
2021-05-26 19:27:41 +08:00
#Start the service in the background
2022-09-13 00:22:34 +08:00
cmd="./${service_filename[$i]} -port ${service_ports[$j]} -prometheus_port ${prome_ports[$j]}"
2022-09-12 20:50:22 +08:00
if [ $i -eq 0 -o $i -eq 1 ]; then
2022-09-12 23:38:34 +08:00
cmd="./${service_filename[$i]} -port ${service_ports[$j]}"
2022-09-12 20:23:45 +08:00
fi
echo $cmd
nohup $cmd >>../logs/openIM.log 2>&1 &
2021-05-26 19:27:41 +08:00
sleep 1
pid="netstat -ntlp|grep $j |awk '{printf \$7}'|cut -d/ -f1"
2022-09-13 00:22:34 +08:00
echo -e "${GREEN_PREFIX}${service_filename[$i]} start success,port number:${service_ports[$j]} pid:$(eval $pid)$COLOR_SUFFIX"
2021-05-26 19:27:41 +08:00
done
2022-04-16 20:17:21 +08:00
done