From d6168cbad9abe52f1a75233170ab11906ed31b23 Mon Sep 17 00:00:00 2001 From: Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Fri, 29 Oct 2021 20:48:43 +0800 Subject: [PATCH] Add files via upload update script --- build_all_service.sh | 30 ++++++++++++++++++++ check_all.sh | 43 ++++++++++++++++++++++++++++ docker_check_service.sh | 33 +++++++++++++++++++++ docker_start_all.sh | 23 +++++++++++++++ function.sh | 11 +++++++ msg_gateway_start.sh | 48 +++++++++++++++++++++++++++++++ msg_transfer_start.sh | 36 +++++++++++++++++++++++ mysql_database_init.sh | 38 +++++++++++++++++++++++++ path_info.cfg | 63 +++++++++++++++++++++++++++++++++++++++++ push_start.sh | 45 +++++++++++++++++++++++++++++ sdk_svr_start.sh | 47 ++++++++++++++++++++++++++++++ start_all.sh | 18 ++++++++++++ start_rpc_service.sh | 59 ++++++++++++++++++++++++++++++++++++++ stop_all.sh | 19 +++++++++++++ style_info.cfg | 9 ++++++ 15 files changed, 522 insertions(+) create mode 100644 build_all_service.sh create mode 100644 check_all.sh create mode 100644 docker_check_service.sh create mode 100644 docker_start_all.sh create mode 100644 function.sh create mode 100644 msg_gateway_start.sh create mode 100644 msg_transfer_start.sh create mode 100644 mysql_database_init.sh create mode 100644 path_info.cfg create mode 100644 push_start.sh create mode 100644 sdk_svr_start.sh create mode 100644 start_all.sh create mode 100644 start_rpc_service.sh create mode 100644 stop_all.sh create mode 100644 style_info.cfg diff --git a/build_all_service.sh b/build_all_service.sh new file mode 100644 index 000000000..6f563b6f6 --- /dev/null +++ b/build_all_service.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +source ./style_info.cfg +source ./path_info.cfg +source ./function.sh + +bin_dir="../bin" +logs_dir="../logs" +sdk_db_dir="../db/sdk/" +#Automatically created when there is no bin, logs folder +if [ ! -d $bin_dir ]; then + mkdir -p $bin_dir +fi +if [ ! -d $logs_dir ]; then + mkdir -p $logs_dir +fi +if [ ! -d $sdk_db_dir ]; then + mkdir -p $sdk_db_dir +fi + +#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/check_all.sh b/check_all.sh new file mode 100644 index 000000000..b984cc10a --- /dev/null +++ b/check_all.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +source ./style_info.cfg +source ./path_info.cfg +source ./function.sh +service_port_name=( + openImApiPort + openImUserPort + openImFriendPort + openImOfflineMessagePort + openImOnlineRelayPort + openImGroupPort + openImAuthPort + openImPushPort + openImWsPort + openImSdkWsPort +) +for i in ${service_port_name[*]}; do + list=$(cat $config_path | grep -w ${i} | awk -F '[:]' '{print $NF}') + list_to_string $list + for j in ${ports_array}; do + port=$(netstat -netulp | grep ./open_im | awk '{print $4}' | grep -w ${j} | awk -F '[:]' '{print $NF}') + if [[ ${port} -ne ${j} ]]; then + echo -e ${YELLOW_PREFIX}${i}${COLOR_SUFFIX}${RED_PREFIX}" service does not start normally,not initiated port is "${COLOR_SUFFIX}${YELLOW_PREFIX}${j}${COLOR_SUFFIX} + echo -e ${RED_PREFIX}"please check ../logs/openIM.log "${COLOR_SUFFIX} + exit -1 + else + echo -e ${j}${GREEN_PREFIX}" port has been listening,belongs service is "${i}${COLOR_SUFFIX} + fi + done +done + +#Check launched service process +check=$(ps aux | grep -w ./${msg_transfer_name} | grep -v grep | wc -l) +if [ $check -eq ${msg_transfer_service_num} ]; then + echo -e ${GREEN_PREFIX}"service has been starting,belongs service is openImMsgTransfer"${COLOR_SUFFIX} +else + echo -e ${RED_PREFIX}"openImMsgTransfer service does not start normally, num err"${COLOR_SUFFIX} + echo -e ${RED_PREFIX}"please check ../logs/openIM.log "${COLOR_SUFFIX} + exit -1 +fi + +echo -e ${YELLOW_PREFIX}"all services launch success"${COLOR_SUFFIX} diff --git a/docker_check_service.sh b/docker_check_service.sh new file mode 100644 index 000000000..c9fd54ec8 --- /dev/null +++ b/docker_check_service.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +source ./style_info.cfg + +docker_compose_components=( + etcd + mongo + mysql + open-im-server + redis + kafka + zookeeper +) + +component_server_count=0 + +for ((i = 0; i < ${#docker_compose_components[*]}; i++)); do + component_server="docker-compose ps|grep -w ${docker_compose_components[$i]}|grep Up" + count="${component_server}|wc -l" + + if [ $(eval ${count}) -gt 0 ]; then + echo -e "${SKY_BLUE_PREFIX}docker-compose ${docker_compose_components[$i]} is Up!${COLOR_SUFFIX}" + let component_server_count+=1 + else + echo -e "${RED_PREFIX} ${docker_compose_components[$i]} start failed!${COLOR_SUFFIX}" + fi +done + +if [ ${component_server_count} -eq 7 ]; then + echo -e "${YELLOW_PREFIX}\ndocker-compose all services is Up!${COLOR_SUFFIX}" +else + echo -e "${RED_PREFIX}\nsome docker-compose services start failed,please check red logs on console ${COLOR_SUFFIX}" +fi diff --git a/docker_start_all.sh b/docker_start_all.sh new file mode 100644 index 000000000..fce59c41a --- /dev/null +++ b/docker_start_all.sh @@ -0,0 +1,23 @@ +#!/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=( + start_rpc_service.sh + msg_gateway_start.sh + push_start.sh + msg_transfer_start.sh + sdk_svr_start.sh +) + +#fixme The 10 second delay to start the project is for the docker-compose one-click to start openIM when the infrastructure dependencies are not started +sleep 10 + +for i in ${need_to_start_server_shell[*]}; do + chmod +x $i + ./$i +done + +#fixme prevents the openIM service exit after execution in the docker container +tail -f /dev/null diff --git a/function.sh b/function.sh new file mode 100644 index 000000000..b57373c72 --- /dev/null +++ b/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/msg_gateway_start.sh b/msg_gateway_start.sh new file mode 100644 index 000000000..c21d335ca --- /dev/null +++ b/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 openImWsPort | 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 1 +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/openIM.log 2>&1 & +done + +#Check launched service process +sleep 3 +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 -w ${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 openIM.log"${COLOR_SUFFIX} +fi diff --git a/msg_transfer_start.sh b/msg_transfer_start.sh new file mode 100644 index 000000000..0b645596c --- /dev/null +++ b/msg_transfer_start.sh @@ -0,0 +1,36 @@ +#!/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 -ge 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} +for ((i = 0; i < ${msg_transfer_service_num}; i++)); do + nohup ./${msg_transfer_name} >>../logs/openIM.log 2>&1 & +done + +#Check launched service process +check=`ps aux | grep -w ./${msg_transfer_name} | grep -v grep| wc -l` +if [ $check -ge 1 ] +then +newPid=`ps aux | grep -w ./${msg_transfer_name} | grep -v grep|awk '{print $2}'` +allPorts="" + 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 openIM.log"${COLOR_SUFFIX} +fi diff --git a/mysql_database_init.sh b/mysql_database_init.sh new file mode 100644 index 000000000..f8e4caa59 --- /dev/null +++ b/mysql_database_init.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +source ./style_info.cfg +source ./path_info.cfg +source ./function.sh + +#define database attributes +address=$(cat $config_path | grep -w dbMysqlAddress) +list_to_string ${address} +hostAndPort=($ports_array) +DATABASE_HOST=$(echo $hostAndPort | awk -F '[:]' '{print $1}') +DATABASE_PORT=$(echo $hostAndPort | awk -F '[:]' '{print $NF}') +DATABASE_USERNAME=$(cat $config_path | grep -w dbMysqlUserName | awk -F '[:]' '{print $NF}') +DATABASE_PWD=`eval echo $(cat $config_path | grep -w dbMysqlPassword | awk -F '[:]' '{print $NF}')` +DATABASE_NAME=$(cat $config_path | grep -w dbMysqlDatabaseName | awk -F '[:]' '{print $NF}') +SQL_FILE="../config/mysql_sql_file/openIM.sql" + + +create_data_sql="create database IF NOT EXISTS $DATABASE_NAME" +set_character_code_sql="alter database $DATABASE_NAME character set utf8mb4 collate utf8mb4_general_ci" + +echo -e "${SKY_BLUE_PREFIX}start to create database.....$COLOR_SUFFIX" +mysql -h $DATABASE_HOST -P $DATABASE_PORT -u $DATABASE_USERNAME -p$DATABASE_PWD -e "$create_data_sql" + +if [ $? -eq 0 ]; then + echo -e "${SKY_BLUE_PREFIX}create database ${DATABASE_NAME} successfully$COLOR_SUFFIX" + mysql -h $DATABASE_HOST -P $DATABASE_PORT -u $DATABASE_USERNAME -p$DATABASE_PWD -e "$set_character_code_sql" +else + echo -e "${RED_PREFIX}create database failed or exists the database$COLOR_SUFFIX\n" +fi + +echo -e "${SKY_BLUE_PREFIX}start to source openIM.sql .....$COLOR_SUFFIX" +mysql -h $DATABASE_HOST -P $DATABASE_PORT -u $DATABASE_USERNAME -p$DATABASE_PWD -D $DATABASE_NAME <$SQL_FILE +if [ $? -eq 0 ]; then + echo -e "${SKY_BLUE_PREFIX}source openIM.sql successfully$COLOR_SUFFIX" +else + echo -e "${RED_PREFIX}source openIM.sql failed$COLOR_SUFFIX\n" +fi diff --git a/path_info.cfg b/path_info.cfg new file mode 100644 index 000000000..4529c93d6 --- /dev/null +++ b/path_info.cfg @@ -0,0 +1,63 @@ +#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/" +msg_transfer_service_num=2 + + +sdk_server_name="open_im_sdk_server" +sdk_server_binary_root="../bin/" +sdk_server_source_root="../src/Open-IM-SDK-Core/" + + +#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} + ${sdk_server_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} + ${sdk_server_name} +) + + + + diff --git a/push_start.sh b/push_start.sh new file mode 100644 index 000000000..51ec1d6ba --- /dev/null +++ b/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 -ge 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/openIM.log 2>&1 & +done + +sleep 3 +#Check launched service process +check=$(ps aux | grep -w ./${push_name} | grep -v grep | wc -l) +if [ $check -ge 1 ]; then + newPid=$(ps aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}') + ports=$(netstat -netulp | grep -w ${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 openIM.log"${COLOR_SUFFIX} +fi diff --git a/sdk_svr_start.sh b/sdk_svr_start.sh new file mode 100644 index 000000000..4d6af3999 --- /dev/null +++ b/sdk_svr_start.sh @@ -0,0 +1,47 @@ +#!/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 openImApiPort | awk -F '[:]' '{print $NF}') +list2=$(cat $config_path | grep openImWsPort | awk -F '[:]' '{print $NF}') +list3=$(cat $config_path | grep openImSdkWsPort | awk -F '[:]' '{print $NF}') +list_to_string $list1 +api_ports=($ports_array) +list_to_string $list2 +ws_ports=($ports_array) +list_to_string $list3 +sdk_ws_ports=($ports_array) + + + + +#Check if the service exists +#If it is exists,kill this process +check=$(ps aux | grep -w ./${sdk_server_name} | grep -v grep | wc -l) +if [ $check -ge 1 ]; then + oldPid=$(ps aux | grep -w ./${sdk_server_name} | grep -v grep | awk '{print $2}') + kill -9 ${oldPid} +fi +#Waiting port recycling +sleep 1 +cd ${sdk_server_binary_root} + nohup ./${sdk_server_name} -openIM_api_port ${api_ports[0]} -openIM_ws_port ${ws_ports[0]} -sdk_ws_port ${sdk_ws_ports[0]} >>../logs/openIM.log 2>&1 & + +#Check launched service process +sleep 3 +check=$(ps aux | grep -w ./${sdk_server_name} | grep -v grep | wc -l) +allPorts="" +if [ $check -ge 1 ]; then + allNewPid=$(ps aux | grep -w ./${sdk_server_name} | grep -v grep | awk '{print $2}') + for i in $allNewPid; do + ports=$(netstat -netulp | grep -w ${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}${sdk_server_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}${sdk_server_name}${COLOR_SUFFIX}${RED_PREFIX}"SERVICE START ERROR PLEASE CHECK openIM.log"${COLOR_SUFFIX} +fi diff --git a/start_all.sh b/start_all.sh new file mode 100644 index 000000000..9990cb6c8 --- /dev/null +++ b/start_all.sh @@ -0,0 +1,18 @@ +#!/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=( + start_rpc_service.sh + msg_gateway_start.sh + push_start.sh + msg_transfer_start.sh + sdk_svr_start.sh +) + +for i in ${need_to_start_server_shell[*]}; do + chmod +x $i + ./$i +done + diff --git a/start_rpc_service.sh b/start_rpc_service.sh new file mode 100644 index 000000000..6307ca1c0 --- /dev/null +++ b/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 >>../logs/openIM.log 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/stop_all.sh b/stop_all.sh new file mode 100644 index 000000000..ef7237ab5 --- /dev/null +++ b/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 diff --git a/style_info.cfg b/style_info.cfg new file mode 100644 index 000000000..92cc5da49 --- /dev/null +++ b/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"