docs: add openim scripts deployment system

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
Xinwei Xiong(cubxxw)
2023-10-26 14:16:08 +08:00
parent 200fbd94a4
commit 104c78dcf4
33 changed files with 616 additions and 545 deletions
+3 -2
View File
@@ -33,8 +33,9 @@ openim::log::info "\n# Begin to check all openim service"
# OpenIM status
# Elegant printing function
print_services_and_ports() {
local -n service_names=$1
local -n service_ports=$2
# 获取数组
declare -g service_names=("${!1}")
declare -g service_ports=("${!2}")
echo "+-------------------------+----------+"
echo "| Service Name | Port |"
+1 -1
View File
@@ -118,7 +118,7 @@ GRAFANA_NETWORK_ADDRESS=$(generate_ip)
# read: https://github.com/openimsdk/open-im-server/blob/main/deployment/init/README.md
def "OPENIM_DATA_DIR" "/data/openim"
def "OPENIM_INSTALL_DIR" "/opt/openim"
def "OPENIM_CONFIG_DIR" "/etc/openim"
def "OPENIM_CONFIG_DIR" "/etc/openim/config"
def "OPENIM_LOG_DIR" "/var/log/openim"
def "CA_FILE" "${OPENIM_CONFIG_DIR}/cert/ca.pem"
+27 -27
View File
@@ -51,15 +51,9 @@
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
source "${OPENIM_ROOT}"/scripts/install/openim-msggateway.sh
source "${OPENIM_ROOT}"/scripts/install/openim-msgtransfer.sh
source "${OPENIM_ROOT}"/scripts/install/openim-push.sh
source "${OPENIM_ROOT}"/scripts/install/openim-rpc.sh
source "${OPENIM_ROOT}"/scripts/install/openim-crontask.sh
source "${OPENIM_ROOT}"/scripts/install/openim-api.sh
source "${OPENIM_ROOT}"/scripts/install/openim-man.sh
source "${OPENIM_ROOT}"/scripts/install/openim-tools.sh
source "${OPENIM_ROOT}"/scripts/install/test.sh
${OPENIM_ROOT}/scripts/install/openim-man.sh
${OPENIM_ROOT}/scripts/install/openim-tools.sh
${OPENIM_ROOT}/scripts/install/test.sh
# Detailed help function
function openim::install::show_help() {
@@ -79,15 +73,21 @@ function openim::install::show_help() {
function openim::install::install_openim()
{
openim::common::sudo "mkdir -p ${OPENIM_DATA_DIR} ${OPENIM_INSTALL_DIR} ${OPENIM_CONFIG_DIR} ${OPENIM_LOG_DIR}"
openim::log::info "check openim dependency"
openim::common::sudo "cp -r ${OPENIM_ROOT}/config/* ${OPENIM_CONFIG_DIR}/"
echo ${LINUX_PASSWORD} | sudo -S bash -c \
"${OPENIM_ROOT}/scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.yaml > ${OPENIM_CONFIG_DIR}/config.yaml"
openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}
openim::msggateway::install || return 1
openim::msgtransfer::install || return 1
openim::push::install || return 1
openim::rpc::install || return 1
openim::crontask::install || return 1
openim::api::install || return 1
${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::install || return 1
${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::install || return 1
${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::install || return 1
${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::install || return 1
${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::install || return 1
${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::install || return 1
openim::log::success "openim install success"
}
@@ -96,12 +96,12 @@ function openim::uninstall::uninstall_openim()
{
openim::log::info "uninstall openim"
openim::msggateway::uninstall || return 1
openim::msgtransfer::uninstall || return 1
openim::push::uninstall || return 1
openim::rpc::uninstall || return 1
openim::crontask::uninstall || return 1
openim::api::uninstall || return 1
${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::uninstall || return 1
${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::uninstall || return 1
${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::uninstall || return 1
${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::uninstall || return 1
${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::uninstall || return 1
${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::uninstall || return 1
openim::log::success "openim uninstall success"
}
@@ -110,12 +110,12 @@ function openim::install::status()
{
openim::log::info "check openim status"
openim::msggateway::status || return 1
openim::msgtransfer::status || return 1
openim::push::status || return 1
openim::rpc::status || return 1
openim::crontask::status || return 1
openim::api::status || return 1
${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::status || return 1
${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::status || return 1
${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::status || return 1
${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::status || return 1
${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::status || return 1
${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::status || return 1
openim::log::success "openim status success"
}
+53 -4
View File
@@ -92,21 +92,70 @@ function openim::api::start_service() {
###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
function openim::api::install() {
openim::log::info "Installing ${SERVER_NAME} ..."
# Print the necessary information after installation
function openim::api::info() {
cat << EOF
openim-api listen on: ${OPENIM_API_HOST}:${API_OPENIM_PORT}
EOF
}
# install openim-api
function openim::api::install() {
openim::log::info "Installing ${SERVER_NAME} ..."
pushd "${OPENIM_ROOT}"
# 1. Build openim-api
make build BINS=${SERVER_NAME}
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
# 2. Generate and install the openim-api configuration file (config)
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.yaml"
# 3. Create and install the ${SERVER_NAME} systemd unit file
echo ${LINUX_PASSWORD} | sudo -S bash -c \
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
# 4. Start the openim-api service
openim::common::sudo "systemctl daemon-reload"
openim::common::sudo "systemctl restart ${SERVER_NAME}"
openim::common::sudo "systemctl enable ${SERVER_NAME}"
openim::api::status || return 1
openim::api::info
openim::log::info "install ${SERVER_NAME} successfully"
popd
}
# Unload
function openim::api::uninstall() {
openim::log::info "Uninstalling ${SERVER_NAME} ..."
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}/${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::api::status() {
openim::log::info "Checking ${SERVER_NAME} 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
}
openim::util::check_ports ${OPENIM_API_PORT_LISTARIES[@]}
}
if [[ "$*" =~ openim::api:: ]];then
eval $*
fi
eval $*
fi
+9 -15
View File
@@ -51,7 +51,7 @@ function openim::crontask::start()
openim::util::stop_services_with_name ${OPENIM_CRONTASK_BINARY}
openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}"
nohup ${OPENIM_CRONTASK_BINARY} >> ${LOG_FILE} 2>&1 &
nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2>&1 &
openim::util::check_process_names ${SERVER_NAME}
}
@@ -72,18 +72,16 @@ function openim::crontask::install()
# 1. Build openim-crontask
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}"
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
# 2. Generate and install the openim-crontask configuration file (openim-crontask.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"
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.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}"
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
# 4. Start the openim-crontask service
@@ -104,7 +102,7 @@ function openim::crontask::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_INSTALL_DIR}/${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
@@ -115,15 +113,11 @@ function openim::crontask::uninstall()
function openim::crontask::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' || {
if systemctl is-active --quiet "${SERVER_NAME}"; then
openim::log::info "${SERVER_NAME} is running successfully."
else
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
}
+7 -10
View File
@@ -74,7 +74,7 @@ SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
# Print the necessary information after installation
function openim::msggateway::info() {
cat << EOF
openim-msggateway listen on: ${OPENIM_MSGGATEWAY_HOST}
openim-msggateway listen on: ${OPENIM_MSGGATEWAY_HOST}:${OPENIM_MESSAGE_GATEWAY_PORT}
EOF
}
@@ -85,18 +85,15 @@ function openim::msggateway::install()
# 1. Build openim-msggateway
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}"
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
# 2. Generate and install the openim-msggateway configuration file (openim-msggateway.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"
# nono
# 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}"
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
# 4. Start the openim-msggateway service
@@ -117,7 +114,7 @@ function openim::msggateway::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_INSTALL_DIR}/${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
@@ -134,7 +131,7 @@ function openim::msggateway::status()
}
# The listening port is hardcode in the configuration file
if echo | telnet 127.0.0.1 7070 2>&1|grep refused &>/dev/null;then
if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_MESSAGE_GATEWAY_PORT} 2>&1|grep refused &>/dev/null;then
openim::log::error "cannot access health check port, ${SERVER_NAME} maybe not startup"
return 1
fi
+9 -13
View File
@@ -95,18 +95,18 @@ function openim::msgtransfer::install()
# 1. Build openim-msgtransfer
make build BINS=${SERVER_NAME}
openim::common::sudo "cp ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin"
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
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"
# nono
# 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}"
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
# 4. Start the openim-msgtransfer service
@@ -127,7 +127,7 @@ 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_INSTALL_DIR}/${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
@@ -138,15 +138,11 @@ function openim::msgtransfer::uninstall()
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' || {
if systemctl is-active --quiet "${SERVER_NAME}"; then
openim::log::info "${SERVER_NAME} is running successfully."
else
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
}
+8 -11
View File
@@ -83,7 +83,7 @@ SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
# Print the necessary information after installation
function openim::push::info() {
cat << EOF
openim-push listen on: ${OPENIM_PUSH_HOST}
openim-push listen on: ${OPENIM_PUSH_HOST}:${OPENIM_PUSH_PORT}
EOF
}
@@ -94,18 +94,15 @@ function openim::push::install()
# 1. Build openim-push
make build BINS=${SERVER_NAME}
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin"
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}"
# 2. Generate and install the openim-push configuration file (openim-push.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"
# 2. Generate and install the openim-push configuration file (config)
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.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}"
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
# 4. Start the openim-push service
@@ -125,7 +122,7 @@ function openim::push::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_INSTALL_DIR}/${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
@@ -142,7 +139,7 @@ function openim::push::status()
}
# The listening port is hardcode in the configuration file
if echo | telnet 127.0.0.1 7071 2>&1|grep refused &>/dev/null;then # Assuming a different port for push
if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_PUSH_PORT} 2>&1|grep refused &>/dev/null;then # Assuming a different port for push
openim::log::error "cannot access health check port, ${SERVER_NAME} maybe not startup"
return 1
fi
+72 -12
View File
@@ -160,26 +160,86 @@ function openim::rpc::start_service() {
}
###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
declare -A SYSTEM_FILE_PATHS
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
SYSTEM_FILE_PATHS["$service"]="/etc/systemd/system/${service}.service"
done
function openim::rpc::install() {
openim::log::info "Installing ${SERVER_NAME} ..."
# Print the necessary information after installation
function openim::rpc::info() {
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
echo "${service} listen on: ${OPENIM_RPC_PORT_LISTARIES[@]}"
done
}
function openim::rpc::uninstall() {
openim::log::info "Uninstalling ${SERVER_NAME} ..."
# install openim-rpc
function openim::rpc::install()
{
pushd "${OPENIM_ROOT}"
# 1. Build openim-rpc
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
make build BINS=${service}
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${service} ${OPENIM_INSTALL_DIR}/${service}"
openim::log::status "${service} binary: ${OPENIM_INSTALL_DIR}/${service}/${service}"
done
# 2. Generate and install the openim-rpc configuration file (config)
openim::log::status "openim-rpc config file: ${OPENIM_CONFIG_DIR}/config.yaml"
# 3. Create and install the systemd unit files
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
echo ${LINUX_PASSWORD} | sudo -S bash -c \
"SERVER_NAME=${service} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATHS[$service]}"
openim::log::status "${service} systemd file: ${SYSTEM_FILE_PATHS[$service]}"
done
# 4. Start the openim-rpc services
openim::common::sudo "systemctl daemon-reload"
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
openim::common::sudo "systemctl restart ${service}"
openim::common::sudo "systemctl enable ${service}"
done
openim::rpc::status || return 1
openim::rpc::info
openim::log::info "install openim-rpc successfully"
popd
}
function openim::rpc::status() {
openim::log::info "Checking ${SERVER_NAME} status ..."
# Unload
function openim::rpc::uninstall()
{
set +o errexit
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
openim::common::sudo "systemctl stop ${service}"
openim::common::sudo "systemctl disable ${service}"
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${service}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${service}.yaml"
openim::common::sudo "rm -f ${SYSTEM_FILE_PATHS[$service]}"
done
set -o errexit
openim::log::info "uninstall openim-rpc successfully"
}
openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]}
# openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]}
# Status Check
function openim::rpc::status()
{
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
# Check the running status of the ${service}. If active (running) is displayed, the ${service} is started successfully.
systemctl status ${service}|grep -q 'active' || {
openim::log::error "${service} failed to start, maybe not installed properly"
return 1
}
openim::util::check_process_names ${SERVER_NAME}
# The listening port is hardcoded in the configuration file
if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_RPC_PORT_LISTARIES[@]} 2>&1|grep refused &>/dev/null;then
openim::log::error "cannot access health check port, ${service} maybe not startup"
return 1
fi
done
}
if [[ "$*" =~ openim::rpc:: ]];then
eval $*
fi
eval $*
fi