diff --git a/docs/open-im-server.png b/docs/open-im-server.png new file mode 100644 index 000000000..35df36f39 Binary files /dev/null and b/docs/open-im-server.png differ diff --git a/script/function.sh b/script/function.sh new file mode 100644 index 000000000..0deb52b38 --- /dev/null +++ b/script/function.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +#input:[10023,2323,3434] +#output:10023 2323 3434 +list_to_string(){ +ports_list=$* +sub_s1=`echo $ports_list | sed 's/ //g'` +sub_s2=${sub_s1//,/ } +sub_s3=${sub_s2#*[} +sub_s4=${sub_s3%]*} +ports_array=$sub_s4 +} \ No newline at end of file diff --git a/script/msg_gateway_start.sh b/script/msg_gateway_start.sh new file mode 100644 index 000000000..c9bcf953c --- /dev/null +++ b/script/msg_gateway_start.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +#Include shell font styles and some basic information +source ./style_info.cfg +source ./path_info.cfg +source ./function.sh +list1=$(cat $config_path | grep openImOnlineRelayPort | awk -F '[:]' '{print $NF}') +list2=$(cat $config_path | grep websocketPort | awk -F '[:]' '{print $NF}') +list_to_string $list1 +rpc_ports=($ports_array) +list_to_string $list2 +ws_ports=($ports_array) +if [ ${#rpc_ports[@]} -ne ${#ws_ports[@]} ]; then + + echo -e ${RED_PREFIX}"ws_ports does not match push_rpc_ports in quantity!!!"${COLOR_SUFFIX} + exit 0 + +fi +#Check if the service exists +#If it is exists,kill this process +check=$(ps aux | grep -w ./${msg_gateway_name} | grep -v grep | wc -l) +if [ $check -ge 1 ]; then + oldPid=$(ps aux | grep -w ./${msg_gateway_name} | grep -v grep | awk '{print $2}') + kill -9 ${oldPid} +fi +#Waiting port recycling +sleep 3 +cd ${msg_gateway_binary_root} +for ((i = 0; i < ${#ws_ports[@]}; i++)); do + nohup ./${msg_gateway_name} -rpc_port ${rpc_ports[$i]} -ws_port ${ws_ports[$i]} >>../logs/${msg_gateway_name}.$(date +%Y-%m-%d).log 2>&1 & +done + +#Check launched service process +sleep 1 +check=$(ps aux | grep -w ./${msg_gateway_name} | grep -v grep | wc -l) +allPorts="" +if [ $check -ge 1 ]; then + allNewPid=$(ps aux | grep -w ./${msg_gateway_name} | grep -v grep | awk '{print $2}') + for i in $allNewPid; do + ports=$(netstat -netulp | grep ${i} | awk '{print $4}' | awk -F '[:]' '{print $NF}') + allPorts=${allPorts}"$ports " + done + echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS !!!"${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${YELLOW_PREFIX}${msg_gateway_name}${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${YELLOW_PREFIX}${allNewPid}${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${YELLOW_PREFIX}${allPorts}${COLOR_SUFFIX} +else + echo -e ${YELLOW_PREFIX}${msg_gateway_name}${COLOR_SUFFIX}${RED_PREFIX}"SERVICE START ERROR !!! PLEASE CHECK ERROR LOG"${COLOR_SUFFIX} +fi diff --git a/script/msg_transfer_start.sh b/script/msg_transfer_start.sh new file mode 100644 index 000000000..dff8320cb --- /dev/null +++ b/script/msg_transfer_start.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +#Include shell font styles and some basic information +source ./style_info.cfg +source ./path_info.cfg + + + +#Check if the service exists +#If it is exists,kill this process +check=`ps aux | grep -w ./${msg_transfer_name} | grep -v grep| wc -l` +if [ $check -eq 1 ] +then +oldPid=`ps aux | grep -w ./${msg_transfer_name} | grep -v grep|awk '{print $2}'` + kill -9 $oldPid +fi +#Waiting port recycling +sleep 1 +cd ${msg_transfer_binary_root} + nohup ./${msg_transfer_name} >>../logs/${msg_transfer_name}.`date +%Y-%m-%d`.log 2>&1 & +#Check launched service process +check=`ps aux | grep -w ./${msg_transfer_name} | grep -v grep| wc -l` +if [ $check -eq 1 ] +then +newPid=`ps aux | grep -w ./${msg_transfer_name} | grep -v grep|awk '{print $2}'` +ports=`netstat -netulp | grep ${newPid}|awk '{print $4}'|awk -F '[:]' '{print $NF}'` +allPorts="" + +for i in $ports ; +do + allPorts=${allPorts}"$i " +done + echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS !!!"${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${YELLOW_PREFIX}${msg_transfer_name}${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${YELLOW_PREFIX}${newPid}${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${YELLOW_PREFIX}${allPorts}${COLOR_SUFFIX} +else + echo -e ${YELLOW_PREFIX}${msg_transfer_name}${COLOR_SUFFIX}${RED_PREFIX}"SERVICE START ERROR !!! PLEASE CHECK ERROR LOG"${COLOR_SUFFIX} +fi diff --git a/script/path_info.cfg b/script/path_info.cfg new file mode 100644 index 000000000..432a7ee1e --- /dev/null +++ b/script/path_info.cfg @@ -0,0 +1,54 @@ +#Don't put the space between "=" +msg_gateway_name="open_im_msg_gateway" +msg_gateway_binary_root="../bin/" +msg_gateway_source_root="../src/msg_gateway/" + +msg_name="open_im_msg" +msg_binary_root="../bin/" +msg_source_root="../src/rpc/chat/" + +push_name="open_im_push" +push_binary_root="../bin/" +push_source_root="../src/push/" + + + +msg_transfer_name="open_im_msg_transfer" +msg_transfer_binary_root="../bin/" +msg_transfer_source_root="../src/msg_transfer/" + +#Global configuration file default dir +config_path="../config/config.yaml" + +#servicefile dir path +service_source_root=( + #api service file + ../src/api/ + #rpc service file + ../src/rpc/user/ + ../src/rpc/friend/ + ../src/rpc/group/ + ../src/rpc/auth/ + ${msg_gateway_source_root} + ${msg_transfer_source_root} + ${msg_source_root} + ${push_source_root} +) +#service filename +service_names=( + #api service filename + open_im_api + #rpc service filename + open_im_user + open_im_friend + open_im_group + open_im_auth + ${msg_gateway_name} + ${msg_transfer_name} + ${msg_name} + ${push_name} +) + + + + diff --git a/script/push_start.sh b/script/push_start.sh new file mode 100644 index 000000000..43fdd9288 --- /dev/null +++ b/script/push_start.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +#Include shell font styles and some basic information +source ./style_info.cfg +source ./path_info.cfg +source ./function.sh + + + +list1=$(cat $config_path | grep openImPushPort | awk -F '[:]' '{print $NF}') +list_to_string $list1 +rpc_ports=($ports_array) + +#Check if the service exists +#If it is exists,kill this process +check=$(ps aux | grep -w ./${push_name} | grep -v grep | wc -l) +if [ $check -eq 1 ]; then + oldPid=$(ps aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}') + kill -9 $oldPid +fi +#Waiting port recycling +sleep 1 +cd ${push_binary_root} + +for ((i = 0; i < ${#rpc_ports[@]}; i++)); do + nohup ./${push_name} -port ${rpc_ports[$i]} >>../logs/${push_name}.$(date +%Y-%m-%d).log 2>&1 & +done + + +#Check launched service process +check=$(ps aux | grep -w ./${push_name} | grep -v grep | wc -l) +if [ $check -eq 1 ]; then + newPid=$(ps aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}') + ports=$(netstat -netulp | grep ${newPid} | awk '{print $4}' | awk -F '[:]' '{print $NF}') + allPorts="" + + for i in $ports; do + allPorts=${allPorts}"$i " + done + echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS !!!"${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${YELLOW_PREFIX}${push_name}${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${YELLOW_PREFIX}${newPid}${COLOR_SUFFIX} + echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${YELLOW_PREFIX}${allPorts}${COLOR_SUFFIX} +else + echo -e ${YELLOW_PREFIX}${push_name}${COLOR_SUFFIX}${RED_PREFIX}"SERVICE START ERROR !!! PLEASE CHECK ERROR LOG"${COLOR_SUFFIX} +fi diff --git a/script/style_info.cfg b/script/style_info.cfg new file mode 100644 index 000000000..ff28dcb88 --- /dev/null +++ b/script/style_info.cfg @@ -0,0 +1,9 @@ +#Shell font formatting information +COLOR_SUFFIX="\033[0m" +BLACK_PREFIX="\033[30m" +RED_PREFIX="\033[31m" +GREEN_PREFIX="\033[32m" +YELLOW_PREFIX="\033[33m" +BLUE_PREFIX="\033[34m" +PURPLE_PREFIX="\033[35m" +SKY_BLUE_PREFIX="\033[36m"