From 7f70cf6c314fef00fc1eb76bd8d1ded4e55faa27 Mon Sep 17 00:00:00 2001 From: away <1819625428@qq.com> Date: Wed, 26 May 2021 19:27:41 +0800 Subject: [PATCH] Shell script initial commit --- script/build_all_service.sh | 16 ++++++++++ script/start_all.sh | 19 ++++++++++++ script/start_rpc_service.sh | 59 +++++++++++++++++++++++++++++++++++++ script/stop_all.sh | 19 ++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 script/build_all_service.sh create mode 100644 script/start_all.sh create mode 100644 script/start_rpc_service.sh create mode 100644 script/stop_all.sh diff --git a/script/build_all_service.sh b/script/build_all_service.sh new file mode 100644 index 0000000..0bceb11 --- /dev/null +++ b/script/build_all_service.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +source ./style_info.cfg +source ./path_info.cfg +source ./function.sh + +#begin path +begin_path=$PWD + +for ((i = 0; i < ${#service_source_root[*]}; i++)); do + cd $begin_path + service_path=${service_source_root[$i]} + cd $service_path && echo -e "${SKY_BLUE_PREFIX}Current directory: $PWD $COLOR_SUFFIX" + make install && echo -e "${SKY_BLUE_PREFIX}build ${service_names[$i]} success,moving binary file to the bin directory${COLOR_SUFFIX}" && + echo -e "${SKY_BLUE_PREFIX}Successful moved ${service_names[$i]} to the bin directory${COLOR_SUFFIX}\n" +done diff --git a/script/start_all.sh b/script/start_all.sh new file mode 100644 index 0000000..15cbfb5 --- /dev/null +++ b/script/start_all.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +#fixme This script is the total startup script +#fixme The full name of the shell script that needs to be started is placed in the need_to_start_server_shell array + +#fixme Put the shell script name here +need_to_start_server_shell=( + auto_start_service.sh + msg_gateway_start.sh + push_start.sh + msg_transfer_start.sh +) + +for i in ${need_to_start_server_shell[*]}; do + chmod +x $i + ./$i +done +while [ true ]; do + sleep 60 +done diff --git a/script/start_rpc_service.sh b/script/start_rpc_service.sh new file mode 100644 index 0000000..ec24945 --- /dev/null +++ b/script/start_rpc_service.sh @@ -0,0 +1,59 @@ +#!/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} +) + +#service config port name +service_port_name=( + #api port name + openImApiPort + #rpc port name + openImUserPort + openImFriendPort + openImGroupPort + openImAuthPort + openImOfflineMessagePort + +) + +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}'" + echo -e "${SKY_BLUE_PREFIX}${service_filename[$i]} service has been started,pid:$(eval $pid)$COLOR_SUFFIX" + echo -e "${SKY_BLUE_PREFIX}Killing the service ${service_filename[$i]} pid:$(eval $pid)${COLOR_SUFFIX}" + #kill the service that existed + kill -9 $(eval $pid) + sleep 0.5 + fi + cd ../bin && echo -e "${SKY_BLUE_PREFIX}${service_filename[$i]} service is starting${COLOR_SUFFIX}" + #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} + #Start related rpc services based on the number of ports + for j in ${ports_array}; do + echo -e "${SKY_BLUE_PREFIX}${service_filename[$i]} Service is starting,port number:$j $COLOR_SUFFIX" + #Start the service in the background + ./${service_filename[$i]} -port $j & + # nohup ./${service_filename[$i]} -port $j >/dev/null 2>&1 & + sleep 1 + pid="netstat -ntlp|grep $j |awk '{printf \$7}'|cut -d/ -f1" + echo -e "${RED_PREFIX}${service_filename[$i]} Service is started,port number:$j pid:$(eval $pid)$COLOR_SUFFIX" + done +done diff --git a/script/stop_all.sh b/script/stop_all.sh new file mode 100644 index 0000000..2e1e119 --- /dev/null +++ b/script/stop_all.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +#fixme This script is to stop the service + +source ./style_info.cfg +source ./path_info.cfg + + +for i in ${service_names[*]}; do + #Check whether the service exists + name="ps -aux |grep -w $i |grep -v grep" + count="${name}| wc -l" + if [ $(eval ${count}) -gt 0 ]; then + pid="${name}| awk '{print \$2}'" + echo -e "${SKY_BLUE_PREFIX}Killing service:$i pid:$(eval $pid)${COLOR_SUFFIX}" + #kill the service that existed + kill -9 $(eval $pid) + echo -e "${SKY_BLUE_PREFIX}service:$i was killed ${COLOR_SUFFIX}" + fi +done -- GitLab