feat: add file save

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
pull/825/head
Xinwei Xiong(cubxxw-openim) 2 years ago
parent c47e073db8
commit 405776d321
No known key found for this signature in database
GPG Key ID: 1BAD6F395338EFDE

@ -79,31 +79,6 @@ IFS=" " read -ra OPENIM_SERVER_PORT_TARGETS <<< "$(openim::common::service_port)
readonly OPENIM_SERVER_PORT_TARGETS
readonly OPENIM_SERVER_PORT_LISTARIES=("${OPENIM_SERVER_PORT_TARGETS[@]##*/}")
openim::rpc::service_name() {
local targets=(
openim-rpc-user
openim-rpc-friend
openim-rpc-msg
openim-rpc-group
openim-rpc-auth
openim-rpc-conversation
openim-rpc-third
)
echo "${targets[@]}"
}
IFS=" " read -ra OPENIM_RPC_SERVICE_TARGETS <<< "$(openim::rpc::service_name)"
readonly OPENIM_RPC_SERVICE_TARGETS
readonly OPENIM_RPC_SERVICE_LISTARIES=("${OPENIM_RPC_SERVICE_TARGETS[@]##*/}")
readonly OPENIM_API_SERVICE_TARGETS=(
openim-api
)
readonly OPENIM_API_SERVICE_LISTARIES=("${OPENIM_API_SERVICE_TARGETS[@]##*/}")
readonly OPENIM_API_PORT_TARGETS=(
${API_OPENIM_PORT}
)
readonly OPENIM_API_PORT_LISTARIES=("${OPENIM_API_PORT_TARGETS[@]##*/}")
# Execute commands that require root permission without entering a password
function openim::common::sudo {

@ -63,6 +63,7 @@ def "OPENIM_CONFIG_DIR" "/etc/openim"
def "OPENIM_LOG_DIR" "/var/log/openim"
def "CA_FILE" "${OPENIM_CONFIG_DIR}/cert/ca.pem"
def "OPNEIM_CONFIG" "${OPENIM_ROOT}/config"
# TODO 注意: 一般的配置都可以使用 def 函数来定义,如果是包含特殊字符,比如说:
# TODO readonly MSG_DESTRUCT_TIME=${MSG_DESTRUCT_TIME:-'0 2 * * *'}
# TODO 使用 readonly 来定义合适,负责无法正常解析, 并且 yaml 模板需要加 "" 来包裹
@ -133,13 +134,14 @@ def "RPC_REGISTER_IP" # RPC的注册IP
def "RPC_LISTEN_IP" "0.0.0.0" # RPC的监听IP
###################### API 配置信息 ######################
def "API_OPENIM_PORT" "10002" # API的开放端口
# API的开放端口
readonly API_OPENIM_PORT=${API_OPENIM_PORT:-'10002'}
def "API_LISTEN_IP" "0.0.0.0" # API的监听IP
###################### RPC Port Configuration Variables ######################
# For launching multiple programs, just fill in multiple ports separated by commas
# For example:
# readonly OPENIM_USER_PORT=${OPENIM_USER_PORT:-'10110, 10111, 10112'}
# readonly OPENIM_USER_PORT=${OPENIM_USER_PORT:-'10110, 10111, 10112'} #Try not to have Spaces
# OpenIM用户服务端口
readonly OPENIM_USER_PORT=${OPENIM_USER_PORT:-'10110'}

@ -31,11 +31,11 @@ openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}"
openim::util::stop_services_with_name ${SERVER_NAME}
# OpenIM message gateway service port
OPENIM_RPC_PORTS=(openim::util::list-to-string ${OPENIM_MESSAGE_GATEWAY_PORT} )
OPENIM_RPC_PORTS=$(openim::util::list-to-string ${OPENIM_MESSAGE_GATEWAY_PORT} )
# OpenIM WS port
OPENIM_WS_PORTS=(openim::util::list-to-string ${OPENIM_WS_PORT} )
OPENIM_WS_PORTS=$(openim::util::list-to-string ${OPENIM_WS_PORT} )
# Message Gateway Prometheus port of the service
MSG_GATEWAY_PROM_PORTS=(openim::util::list-to-string ${MSG_GATEWAY_PROM_PORT} )
MSG_GATEWAY_PROM_PORTS=$(openim::util::list-to-string ${MSG_GATEWAY_PROM_PORT} )
openim::log::status "OpenIM RPC ports: ${OPENIM_RPC_PORTS[*]}"
openim::log::status "OpenIM WS ports: ${OPENIM_WS_PORTS[*]}"

@ -57,8 +57,8 @@ openim::util::stop_services_with_name ${SERVER_NAME}
openim::log::status "prepare start push process, path: ${OPENIM_PUSH_BINARY}"
openim::log::status "prepare start push process, port: ${OPENIM_PUSH_PORT}, prometheus port: ${PUSH_PROM_PORT}"
OPENIM_PUSH_PORTS_ARRAY=(openim::util::list-to-string ${OPENIM_PUSH_PORT} )
PUSH_PROM_PORTS_ARRAY=(openim::util::list-to-string ${PUSH_PROM_PORT} )
OPENIM_PUSH_PORTS_ARRAY=$(openim::util::list-to-string ${OPENIM_PUSH_PORT} )
PUSH_PROM_PORTS_ARRAY=$(openim::util::list-to-string ${PUSH_PROM_PORT} )
openim::log::status "push port list: ${OPENIM_PUSH_PORTS_ARRAY[@]}"
openim::log::status "prometheus port list: ${PUSH_PROM_PORTS_ARRAY[@]}"

@ -22,6 +22,33 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh
SERVER_NAME="openim-rpc"
readonly OPENIM_RPC_CONFIG=${OPENIM_ROOT}/config
openim::rpc::service_name() {
local targets=(
openim-rpc-user
openim-rpc-friend
openim-rpc-msg
openim-rpc-group
openim-rpc-auth
openim-rpc-conversation
openim-rpc-third
)
echo "${targets[@]}"
}
IFS=" " read -ra OPENIM_RPC_SERVICE_TARGETS <<< "$(openim::rpc::service_name)"
readonly OPENIM_RPC_SERVICE_TARGETS
readonly OPENIM_RPC_SERVICE_LISTARIES=("${OPENIM_RPC_SERVICE_TARGETS[@]##*/}")
readonly OPENIM_API_SERVICE_TARGETS=(
openim-api
)
readonly OPENIM_API_SERVICE_LISTARIES=("${OPENIM_API_SERVICE_TARGETS[@]##*/}")
readonly OPENIM_API_PORT_TARGETS=(
${API_OPENIM_PORT}
)
readonly OPENIM_API_PORT_LISTARIES=("${OPENIM_API_PORT_TARGETS[@]##*/}")
readonly OPENIM_RPC_ALL_NAME_TARGETS=(
"${OPENIM_API_SERVICE_TARGETS[@]}"
@ -78,6 +105,10 @@ readonly OPENIM_RPC_ALL_PROM_PORT_TARGETS=(
)
readonly OPENIM_RPC_ALL_PROM_PORT_LISTARIES=("${OPENIM_RPC_ALL_PROM_PORT_TARGETS[@]##*/}")
echo "OPENIM_RPC_ALL_NAME_TARGETS: ${OPENIM_RPC_ALL_NAME_TARGETS[@]}"
echo "OPENIM_RPC_ALL_PROM_PORT_TARGETS: ${OPENIM_RPC_ALL_PROM_PORT_TARGETS[@]}"
echo "OPENIM_RPC_ALL_PORT_TARGETS: ${OPENIM_RPC_ALL_PORT_TARGETS[@]}"
openim::log::info "Starting ${SERVER_NAME} ..."
printf "+------------------------+-------+-----------------+\n"
@ -91,121 +122,78 @@ for ((i=0; i<$length; i++)); do
printf "+------------------------+-------+-----------------+\n"
done
# #service filename
# service_filename=(
# #api
# openim-api
# #rpc
# openim-rpc-user
# openim-rpc-friend
# openim-rpc-msg
# openim-rpc-group
# openim-rpc-auth
# openim-rpc-conversation
# openim-rpc-third
# )
# #service config port name
# service_port_name=(
# #api port name
# openImApiPort
# #rpc port name
# openImUserPort 10110
# openImFriendPort 10120
# openImMessagePort 10130
# openImGroupPort 10150
# openImAuthPort 10160
# openImConversationPort 10180
# openImThirdPort 10190
# )
# service_prometheus_port_name=(
# #api port name
# openImApiPort //${API_OPENIM_PORT}
# #rpc port name
# userPrometheusPort
# friendPrometheusPort
# groupPrometheusPort
# authPrometheusPort
# messagePrometheusPort
# conversationPrometheusPort
# thirdPrometheusPort
# )
# This function starts a service based on the provided filename, port, and optional Prometheus port.
start_service() {
local cmd="./$1 --port $2 -c ${configfile_path}"
if [ -n "$3" ]; then
cmd="${cmd} --prometheus_port $3"
fi
echo "=====================start $1======================" >>$OPENIM_ROOT/logs/openIM.log
nohup $cmd >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
sleep 1
local pid="netstat -ntlp|grep $2 |awk '{printf \$7}'|cut -d/ -f1"
echo -e "${GREEN_PREFIX}$1 start success, port number:$2 pid:$(eval $pid)$COLOR_SUFFIX"
}
cd $OPENIM_ROOT
cd $BIN_DIR
function openim::rpc::start_service() {
local binary_name="$1"
local service_port="$2"
local prometheus_port="$3"
echo "xxxxxxxxxxxxxxxxxxxxxxxx ${#OPENIM_RPC_ALL_NAME_TARGETS[*]}"
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_RPC_CONFIG}"
openim::util::stop_services_with_name ${#OPENIM_RPC_ALL_NAME_TARGETS[*]}
if [ -n "${prometheus_port}" ]; then
printf "Specifying prometheus port: %s\n" "${prometheus_port}"
cmd="${cmd} --prometheus_port ${prometheus_port}"
fi
nohup ${cmd} >> "${LOG_FILE}" 2>&1 &
}
# Assuming OPENIM_RPC_ALL_NAME_TARGETS and other variables have been defined from the previous refactor.
# start all rpc services
for ((i = 0; i < ${#OPENIM_RPC_ALL_NAME_TARGETS[*]}; i++)); do
openim::util::stop_services_with_name "${OPENIM_RPC_ALL_NAME_TARGETS[$i]}"
openim::util::stop_services_with_name ${OPENIM_RPC_ALL_NAME_TARGETS[$i]}
openim::log::info "OpenIM ${OPENIM_RPC_ALL_NAME_TARGETS[$i]} config path: ${OPENIM_RPC_CONFIG}"
# Get the service and Prometheus ports.
service_ports=($(cat $config_path | grep ${OPENIM_RPC_ALL_PORT_TARGETS[$i]} | awk -F '[:]' '{print $NF}'))
prome_ports=($(cat $config_path | grep ${OPENIM_RPC_ALL_PROM_PORT_TARGETS[$i]} | awk -F '[:]' '{print $NF}'))
OPENIM_RPC_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_ALL_PORT_LISTARIES[$i]}) )
OPENIM_RPC_PROM_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_ALL_PROM_PORT_LISTARIES[$i]}) )
for ((j = 0; j < ${#service_ports[*]}; j++)); do
start_service "${OPENIM_RPC_ALL_NAME_TARGETS[$i]}" "${service_ports[$j]}" "${prome_ports[$j]}"
for ((j = 0; j < ${#OPENIM_RPC_SERVICE_PORTS[@]}; j++)); do
openim::log::info "Starting ${OPENIM_RPC_ALL_NAME_TARGETS[$i]} service, port: ${OPENIM_RPC_SERVICE_PORTS[j]}, prometheus port: ${OPENIM_RPC_PROM_PORTS[j]}, binary root: ${OPENIM_OUTPUT_HOSTBIN}/${OPENIM_RPC_ALL_NAME_TARGETS[$i]}"
openim::rpc::start_service "${OPENIM_RPC_ALL_NAME_TARGETS[$i]}" "${OPENIM_RPC_SERVICE_PORTS[j]}" "${OPENIM_RPC_PROM_PORTS[j]}"
done
done
openim::util::check_ports ${OPENIM_RPC_ALL_PORT_TARGETS[@]}
openim::util::check_ports ${OPENIM_RPC_ALL_PROM_PORT_TARGETS[@]}
# ---
for ((i = 0; i < ${#service_filename[*]}; i++)); do
#Check whether the service exists
service_name="ps |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 "${service_filename[$i]} service has been started,pid:$(eval $pid)"
echo "killing the service ${service_filename[$i]} pid:$(eval $pid)"
#kill the service that existed
kill -9 $(eval $pid)
sleep 0.5
fi
cd $OPENIM_ROOT
cd $BIN_DIR
# Get the rpc port in the configuration file
portList=$(cat $config_path | grep ${service_port_name[$i]} | awk -F '[:]' '{print $NF}')
openim::util::list-to-string ${portList}
service_ports=($ports_array)
portList2=$(cat $config_path | grep ${service_prometheus_port_name[$i]} | awk -F '[:]' '{print $NF}')
openim::util::list-to-string $portList2
prome_ports=($ports_array)
#Start related rpc services based on the number of ports
for ((j = 0; j < ${#service_ports[*]}; j++)); do
#Start the service in the background
if [ -z "${prome_ports[$j]}" ]; then
cmd="./${service_filename[$i]} --port ${service_ports[$j]} -c ${configfile_path} "
else
cmd="./${service_filename[$i]} --port ${service_ports[$j]} --prometheus_port ${prome_ports[$j]} -c ${configfile_path} "
fi
if [ $i -eq 0 -o $i -eq 1 ]; then
cmd="./${service_filename[$i]} --port ${service_ports[$j]}"
fi
echo "=====================start ${service_filename[$i]}======================">>$OPENIM_ROOT/logs/openIM.log
nohup $cmd >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
sleep 1
pid="netstat -ntlp|grep $j |awk '{printf \$7}'|cut -d/ -f1"
echo -e "${GREEN_PREFIX}${service_filename[$i]} start success,port number:${service_ports[$j]} pid:$(eval $pid)$COLOR_SUFFIX"
done
done
# for ((i = 0; i < ${#service_filename[*]}; i++)); do
# #Check whether the service exists
# service_name="ps |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 "${service_filename[$i]} service has been started,pid:$(eval $pid)"
# echo "killing the service ${service_filename[$i]} pid:$(eval $pid)"
# #kill the service that existed
# kill -9 $(eval $pid)
# sleep 0.5
# fi
# cd $OPENIM_ROOT
# cd $BIN_DIR
# # Get the rpc port in the configuration file
# portList=$(cat $config_path | grep ${service_port_name[$i]} | awk -F '[:]' '{print $NF}')
# openim::util::list-to-string ${portList}
# service_ports=($ports_array)
# portList2=$(cat $config_path | grep ${service_prometheus_port_name[$i]} | awk -F '[:]' '{print $NF}')
# openim::util::list-to-string $portList2
# prome_ports=($ports_array)
# #Start related rpc services based on the number of ports
# for ((j = 0; j < ${#service_ports[*]}; j++)); do
# #Start the service in the background
# if [ -z "${prome_ports[$j]}" ]; then
# cmd="./${service_filename[$i]} --port ${service_ports[$j]} -c ${configfile_path} "
# else
# cmd="./${service_filename[$i]} --port ${service_ports[$j]} --prometheus_port ${prome_ports[$j]} -c ${configfile_path} "
# fi
# if [ $i -eq 0 -o $i -eq 1 ]; then
# cmd="./${service_filename[$i]} --port ${service_ports[$j]}"
# fi
# echo "=====================start ${service_filename[$i]}======================">>$OPENIM_ROOT/logs/openIM.log
# nohup $cmd >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
# sleep 1
# pid="netstat -ntlp|grep $j |awk '{printf \$7}'|cut -d/ -f1"
# echo -e "${GREEN_PREFIX}${service_filename[$i]} start success,port number:${service_ports[$j]} pid:$(eval $pid)$COLOR_SUFFIX"
# done
# done

@ -897,6 +897,8 @@ function openim::util::list-to-string() {
# For external use, we might want to echo the result so that it can be captured by callers
echo "$ports_array"
}
# MSG_GATEWAY_PROM_PORTS=$(openim::util::list-to-string "10023, 2323, 34 34")
# echo ${MSG_GATEWAY_PROM_PORTS}
# Downloads cfssl/cfssljson/cfssl-certinfo into $1 directory if they do not already exist in PATH
#

Loading…
Cancel
Save