Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>pull/825/head
parent
714d5036df
commit
97e558eb92
@ -1,70 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright © 2023 OpenIM. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set -o errexit
|
||||
set +o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
[[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/lib/init.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
|
||||
bin_dir="$BIN_DIR"
|
||||
logs_dir="$OPENIM_ROOT/logs"
|
||||
|
||||
cd $OPENIM_ROOT
|
||||
|
||||
list1=$(cat $config_path | grep messageTransferPrometheusPort | awk -F '[:]' '{print $NF}')
|
||||
openim::util::list-to-string $list1
|
||||
prome_ports=($ports_array)
|
||||
|
||||
#Check if the service exists
|
||||
#If it is exists,kill this process
|
||||
check=`ps | grep -w ./${openim_msgtransfer} | grep -v grep| wc -l`
|
||||
if [ $check -ge 1 ]
|
||||
then
|
||||
oldPid=`ps | grep -w ./${openim_msgtransfer} | 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
|
||||
prome_port=${prome_ports[$i]}
|
||||
cmd="nohup ./${openim_msgtransfer} --config_folder_path ${configfile_path} "
|
||||
if [ $prome_port != "" ]; then
|
||||
cmd="$cmd --prometheus_port $prome_port --config_folder_path ${configfile_path} "
|
||||
fi
|
||||
echo "==========================start msg_transfer server===========================">>$OPENIM_ROOT/logs/openIM.log
|
||||
$cmd >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
done
|
||||
|
||||
#Check launched service process
|
||||
check=`ps | grep -w ./${openim_msgtransfer} | grep -v grep| wc -l`
|
||||
if [ $check -ge 1 ]
|
||||
then
|
||||
newPid=`ps | grep -w ./${openim_msgtransfer} | 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}${BACKGROUND_GREEN}${openim_msgtransfer}${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${newPid}${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${allPorts}${COLOR_SUFFIX}
|
||||
else
|
||||
echo -e ${BACKGROUND_GREEN}${openim_msgtransfer}${COLOR_SUFFIX}${RED_PREFIX}"\n SERVICE START ERROR, PLEASE CHECK openIM.log"${COLOR_SUFFIX}
|
||||
fi
|
@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright © 2023 OpenIM. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Common utilities, variables and checks for all build scripts.
|
||||
set -o errexit
|
||||
set +o nounset
|
||||
set -o pipefail
|
||||
|
||||
ulimit -n 200000
|
||||
|
||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
[[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh
|
||||
|
||||
SERVER_NAME="openim-msgtransfer"
|
||||
|
||||
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
|
||||
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGTRANSFER_BINARY}"
|
||||
|
||||
openim::util::stop_services_with_name ${SERVER_NAME}
|
||||
|
||||
# Message Transfer 服务的 Prometheus 端口列表
|
||||
MSG_TRANSFER_PROM_PORTS=(openim::util::list-to-string ${MSG_TRANSFER_PROM_PORT} )
|
||||
|
||||
openim::log::status "OpenIM Prometheus ports: ${MSG_TRANSFER_PROM_PORTS[@]}"
|
||||
|
||||
openim::log::status "OpenIM Msggateway config path: ${OPENIM_MSGTRANSFER_CONFIG}"
|
||||
|
||||
openim::log::info "openim maggateway num: ${OPENIM_MSGGATEWAY_NUM}"
|
||||
|
||||
if [ "${OPENIM_MSGGATEWAY_NUM}" -lt 1 ]; then
|
||||
opeim::log::error_exit "OPENIM_MSGGATEWAY_NUM must be greater than 0"
|
||||
fi
|
||||
|
||||
if [ ${OPENIM_MSGGATEWAY_NUM} -ne ${#MSG_TRANSFER_PROM_PORTS[@]} -1]; then
|
||||
openim::log::error_exit "OPENIM_MSGGATEWAY_NUM must be equal to the number of MSG_TRANSFER_PROM_PORTS"
|
||||
fi
|
||||
|
||||
for (( i=1; i<=$OPENIM_MSGGATEWAY_NUM; i++ )) do
|
||||
openim::log::info "prometheus port: ${MSG_TRANSFER_PROM_PORTS[$i]}"
|
||||
|
||||
PROMETHEUS_PORT_OPTION=""
|
||||
if [[ -n "${OPENIM_PROMETHEUS_PORTS[$i]}" ]]; then
|
||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${OPENIM_PROMETHEUS_PORTS[$i]}"
|
||||
fi
|
||||
|
||||
nohup ${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} >> ${LOG_FILE} 2>&1 &
|
||||
done
|
||||
|
||||
openim::util::check_process_names ${SERVER_NAME}
|
||||
|
||||
|
||||
###################################### Linux Systemd ######################################
|
||||
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
|
||||
|
||||
# Print the necessary information after installation
|
||||
function openim::msgtransfer::info() {
|
||||
cat << EOF
|
||||
openim-msgtransfer listen on: ${OPENIM_MSGTRANSFER_HOST}
|
||||
EOF
|
||||
}
|
||||
|
||||
# install openim-msgtransfer
|
||||
function openim::msgtransfer::install()
|
||||
{
|
||||
pushd ${OPENIM_ROOT}
|
||||
|
||||
# 1. Build openim-msgtransfer
|
||||
make build BINS=${SERVER_NAME}
|
||||
openim::common::sudo "cp ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin"
|
||||
|
||||
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}"
|
||||
|
||||
# 2. Generate and install the openim-msgtransfer configuration file (openim-msgtransfer.yaml)
|
||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/${SERVER_NAME}.yaml > ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
|
||||
# 3. Create and install the ${SERVER_NAME} systemd unit file
|
||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/init/${SERVER_NAME}.service > ${SYSTEM_FILE_PATH}"
|
||||
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
|
||||
|
||||
# 4. Start the openim-msgtransfer service
|
||||
openim::common::sudo "systemctl daemon-reload"
|
||||
openim::common::sudo "systemctl restart ${SERVER_NAME}"
|
||||
openim::common::sudo "systemctl enable ${SERVER_NAME}"
|
||||
openim::msgtransfer::status || return 1
|
||||
openim::msgtransfer::info
|
||||
|
||||
openim::log::info "install ${SERVER_NAME} successfully"
|
||||
popd
|
||||
}
|
||||
|
||||
|
||||
# Unload
|
||||
function openim::msgtransfer::uninstall()
|
||||
{
|
||||
set +o errexit
|
||||
openim::common::sudo "systemctl stop ${SERVER_NAME}"
|
||||
openim::common::sudo "systemctl disable ${SERVER_NAME}"
|
||||
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}"
|
||||
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
|
||||
set -o errexit
|
||||
openim::log::info "uninstall ${SERVER_NAME} successfully"
|
||||
}
|
||||
|
||||
# Status Check
|
||||
function openim::msgtransfer::status()
|
||||
{
|
||||
# Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully.
|
||||
systemctl status ${SERVER_NAME}|grep -q 'active' || {
|
||||
openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly"
|
||||
return 1
|
||||
}
|
||||
|
||||
# The listening port is hardcode in the configuration file
|
||||
if echo | telnet 127.0.0.1 7070 2>&1|grep refused &>/dev/null;then
|
||||
openim::log::error "cannot access health check port, ${SERVER_NAME} maybe not startup"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ "$*" =~ ${SERVER_NAME}:: ]];then
|
||||
eval $*
|
||||
fi
|
Loading…
Reference in new issue