From d3364e374f501cb5fefcc37adc09808458a90037 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Mon, 21 Aug 2023 22:18:21 +0800 Subject: [PATCH] feat: add more scrips Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- scripts/install/README.md | 33 +++++++++- scripts/install/install.sh | 52 +++++++++++++--- scripts/install/openim-api.sh | 87 ++++++++++++++------------- scripts/install/openim-crontask.sh | 17 +++--- scripts/install/openim-msggateway.sh | 60 +++++++++--------- scripts/install/openim-msgtransfer.sh | 54 +++++++++-------- scripts/install/openim-push.sh | 39 ++++++------ scripts/install/openim-rpc.sh | 76 +++++++++++++---------- scripts/start-all.sh | 15 ++++- scripts/update-generated-docs.sh | 35 +++++++++++ 10 files changed, 299 insertions(+), 169 deletions(-) create mode 100644 scripts/update-generated-docs.sh diff --git a/scripts/install/README.md b/scripts/install/README.md index d00453133..8e710add8 100644 --- a/scripts/install/README.md +++ b/scripts/install/README.md @@ -25,7 +25,7 @@ The OpenIM Suite represents a comprehensive collection of scripts, each tailored 12. **openim-rpc-third:** Script dedicated to third-party integrations with OpenIM RPC. 13. **openim-rpc-user:** Control interface for OpenIM RPC User operations. -## Usage +## OpenIM Server Installation Script Usage The scripts within the OpenIM Suite generally adhere to two primary execution methodologies. To illustrate these methodologies, we'll use `openim-crontask` as a representative example. @@ -38,9 +38,38 @@ The scripts within the OpenIM Suite generally adhere to two primary execution me 2. **Function-based Execution:** Invoking specific functions within the script for more specialized operations (e.g., install, uninstall). ```bash - ./scripts/install/install.sh [function-name] + ./scripts/install/install.sh [options] ``` +**Description:** +This script is designed to handle the installation, uninstallation, and status checking of OpenIM components on the server. OpenIM is a presumed communication or messaging platform. + +### Commands: +- **-i, --install**: + Initiate the installation of all OpenIM components. + +- **-u, --uninstall**: + Uninstall or remove all OpenIM components from the server. + +- **-s, --status**: + Check and report the current operational status of the installed OpenIM components. + +- **-h, --help**: + Display the help menu for available commands. + +### Example Usage: +To install all OpenIM components: +```bash +./scripts/install/install.sh -i +``` +or +```bash +./scripts/install/install.sh --install +``` +> **Note**: +> Ensure you have the necessary privileges to execute installation or uninstallation operations. It's generally recommended to take a backup before making major changes. + + ### 1. Direct Script Execution This method involves invoking the script directly, initiating its default behavior. For instance, with `openim-crontask`, direct execution will start the OpenIM CronTask as a background process. diff --git a/scripts/install/install.sh b/scripts/install/install.sh index 045674577..7ea5a7a4b 100755 --- a/scripts/install/install.sh +++ b/scripts/install/install.sh @@ -13,11 +13,43 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# OpenIM Server Installation Script +# +# Description: +# This script is designed to handle the installation, uninstallation, and +# status checking of OpenIM components on the server. OpenIM is a presumed +# communication or messaging platform based on the context. +# +# Usage: +# To utilize this script, you need to invoke it with specific commands +# and options as detailed below. +# +# Commands: +# -i, --install : Use this command to initiate the installation of all +# OpenIM components. +# -u, --uninstall : Use this command to uninstall or remove all +# OpenIM components from the server. +# -s, --status : This command can be used to check and report the +# current operational status of the installed OpenIM components. +# -h, --help : For any assistance or to view the available commands, +# use this command to display the help menu. +# +# Example Usage: +# To install all OpenIM components: +# ./scripts/install/install.sh -i +# or +# ./scripts/install/install.sh --install +# +# Note: +# Ensure you have the necessary privileges to execute installation or +# uninstallation operations. It's generally recommended to take a backup +# before making major changes. +# +############################################################################### OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P) [[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh -source ${OPENIM_ROOT}/scripts/install/dependency.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 @@ -28,7 +60,7 @@ source ${OPENIM_ROOT}/scripts/install/test.sh source ${OPENIM_ROOT}/scripts/install/man.sh # Detailed help function -function show_help() { +function openim::install::show_help() { echo "OpenIM Installer" echo "Usage: $0 [options]" echo "" @@ -86,6 +118,12 @@ function openim::install::status() openim::log::success "openim status success" } +# If no arguments are provided, show help +if [[ $# -eq 0 ]]; then + openim::install::show_help + exit 0 +fi + # Argument parsing to call functions based on user input while (( "$#" )); do case "$1" in @@ -102,14 +140,8 @@ while (( "$#" )); do shift ;; -h|--help|*) - show_help + openim::install::show_help exit 0 ;; esac -done - -# If no arguments are provided, show help -if [[ $# -eq 0 ]]; then - show_help - exit 0 -fi \ No newline at end of file +done \ No newline at end of file diff --git a/scripts/install/openim-api.sh b/scripts/install/openim-api.sh index f11b27fd6..b7cd1da7b 100755 --- a/scripts/install/openim-api.sh +++ b/scripts/install/openim-api.sh @@ -33,22 +33,47 @@ readonly OPENIM_API_SERVICE_TARGETS=( ) readonly OPENIM_API_SERVICE_LISTARIES=("${OPENIM_API_SERVICE_TARGETS[@]##*/}") -echo "++ OPENIM_API_SERVICE_LISTARIES: ${OPENIM_API_SERVICE_LISTARIES[@]}" -echo "++ OPENIM_API_PORT_LISTARIES: ${OPENIM_API_PORT_LISTARIES[@]}" -echo "++ OpenIM API config path: ${OPENIM_API_CONFIG}" - -openim::log::info "Starting ${SERVER_NAME} ..." - -printf "+------------------------+--------------+\n" -printf "| Service Name | Port |\n" -printf "+------------------------+--------------+\n" - -length=${#OPENIM_API_SERVICE_LISTARIES[@]} - -for ((i=0; i<$length; i++)); do - printf "| %-22s | %6s |\n" "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}" - printf "+------------------------+--------------+\n" -done +function openim::api::start() +{ + echo "++ OPENIM_API_SERVICE_LISTARIES: ${OPENIM_API_SERVICE_LISTARIES[@]}" + echo "++ OPENIM_API_PORT_LISTARIES: ${OPENIM_API_PORT_LISTARIES[@]}" + echo "++ OpenIM API config path: ${OPENIM_API_CONFIG}" + + openim::log::info "Starting ${SERVER_NAME} ..." + + printf "+------------------------+--------------+\n" + printf "| Service Name | Port |\n" + printf "+------------------------+--------------+\n" + + length=${#OPENIM_API_SERVICE_LISTARIES[@]} + + for ((i=0; i<$length; i++)); do + printf "| %-22s | %6s |\n" "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}" + printf "+------------------------+--------------+\n" + done + # start all api services + for ((i = 0; i < ${#OPENIM_API_SERVICE_LISTARIES[*]}; i++)); do + openim::util::stop_services_with_name ${OPENIM_API_SERVICE_LISTARIES[$i]} + openim::log::info "OpenIM ${OPENIM_API_SERVICE_LISTARIES[$i]} config path: ${OPENIM_API_CONFIG}" + + # Get the service and Prometheus ports. + OPENIM_API_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_API_PORT_LISTARIES[$i]}) ) + + # TODO Only one port is supported. An error occurs on multiple ports + if [ ${#OPENIM_API_SERVICE_PORTS[@]} -ne 1 ]; then + openim::log::error_exit "Set only one port for ${OPENIM_API_SERVICE_LISTARIES[$i]} service." + fi + + for ((j = 0; j < ${#OPENIM_API_SERVICE_PORTS[@]}; j++)); do + openim::log::info "Starting ${OPENIM_API_SERVICE_LISTARIES[$i]} service, port: ${OPENIM_API_SERVICE_PORTS[j]}, binary root: ${OPENIM_OUTPUT_HOSTBIN}/${OPENIM_API_SERVICE_LISTARIES[$i]}" + openim::api::start_service "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[j]}" + sleep 1 + done + done + + OPENIM_API_PORT_STRINGARIES=( $(openim::util::list-to-string ${OPENIM_API_PORT_LISTARIES[@]}) ) + openim::util::check_ports ${OPENIM_API_PORT_STRINGARIES[@]} +} function openim::api::start_service() { local binary_name="$1" @@ -64,44 +89,24 @@ function openim::api::start_service() { fi } -# start all api services -for ((i = 0; i < ${#OPENIM_API_SERVICE_LISTARIES[*]}; i++)); do - openim::util::stop_services_with_name ${OPENIM_API_SERVICE_LISTARIES[$i]} - openim::log::info "OpenIM ${OPENIM_API_SERVICE_LISTARIES[$i]} config path: ${OPENIM_API_CONFIG}" - - # Get the service and Prometheus ports. - OPENIM_API_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_API_PORT_LISTARIES[$i]}) ) - - # TODO Only one port is supported. An error occurs on multiple ports - if [ ${#OPENIM_API_SERVICE_PORTS[@]} -ne 1 ]; then - openim::log::error_exit "Set only one port for ${OPENIM_API_SERVICE_LISTARIES[$i]} service." - fi - - for ((j = 0; j < ${#OPENIM_API_SERVICE_PORTS[@]}; j++)); do - openim::log::info "Starting ${OPENIM_API_SERVICE_LISTARIES[$i]} service, port: ${OPENIM_API_SERVICE_PORTS[j]}, binary root: ${OPENIM_OUTPUT_HOSTBIN}/${OPENIM_API_SERVICE_LISTARIES[$i]}" - openim::api::start_service "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[j]}" - sleep 1 - done -done - -OPENIM_API_PORT_STRINGARIES=( $(openim::util::list-to-string ${OPENIM_API_PORT_LISTARIES[@]}) ) -openim::util::check_ports ${OPENIM_API_PORT_STRINGARIES[@]} - ###################################### Linux Systemd ###################################### SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" function openim::api::install() { - + openim::log::info "Installing ${SERVER_NAME} ..." } function openim::api::uninstall() { + openim::log::info "Uninstalling ${SERVER_NAME} ..." } function openim::api::status() { + openim::log::info "Checking ${SERVER_NAME} status ..." + openim::util::check_ports ${OPENIM_API_PORT_LISTARIES[@]} } -if [[ "$*" =~ ${SERVER_NAME}:: ]];then +if [[ "$*" =~ openim::api:: ]];then eval $* fi \ No newline at end of file diff --git a/scripts/install/openim-crontask.sh b/scripts/install/openim-crontask.sh index 11f5ad42d..2d5ecd1bd 100755 --- a/scripts/install/openim-crontask.sh +++ b/scripts/install/openim-crontask.sh @@ -44,14 +44,17 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P) SERVER_NAME="openim-crontask" -openim::log::info "Start OpenIM Cron, binary root: ${SERVER_NAME}" -openim::log::status "Start OpenIM Cron, path: ${OPENIM_CRONTASK_BINARY}" +function openim::crontask::start() +{ + openim::log::info "Start OpenIM Cron, binary root: ${SERVER_NAME}" + openim::log::status "Start OpenIM Cron, path: ${OPENIM_CRONTASK_BINARY}" -openim::util::stop_services_with_name ${SERVER_NAME} + openim::util::stop_services_with_name ${SERVER_NAME} -openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}" -nohup ${OPENIM_CRONTASK_BINARY} >> ${LOG_FILE} 2>&1 & -openim::util::check_process_names ${SERVER_NAME} + openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}" + nohup ${OPENIM_CRONTASK_BINARY} >> ${LOG_FILE} 2>&1 & + openim::util::check_process_names ${SERVER_NAME} +} ###################################### Linux Systemd ###################################### SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" @@ -125,6 +128,6 @@ function openim::crontask::status() fi } -if [[ "$*" =~ ${SERVER_NAME}:: ]];then +if [[ "$*" =~ openim::crontask:: ]];then eval $* fi diff --git a/scripts/install/openim-msggateway.sh b/scripts/install/openim-msggateway.sh index a390f5a30..6adac9dc1 100755 --- a/scripts/install/openim-msggateway.sh +++ b/scripts/install/openim-msggateway.sh @@ -25,42 +25,44 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P) SERVER_NAME="openim-msggateway" -openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}" -openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}" +function openim::msggateway::start() +{ + openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}" + openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}" -openim::util::stop_services_with_name ${SERVER_NAME} + 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 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} ) + # OpenIM message gateway service 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} ) + # Message Gateway Prometheus port of the service + 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[*]}" -openim::log::status "OpenIM Prometheus ports: ${MSG_GATEWAY_PROM_PORTS[*]}" + openim::log::status "OpenIM RPC ports: ${OPENIM_RPC_PORTS[*]}" + openim::log::status "OpenIM WS ports: ${OPENIM_WS_PORTS[*]}" + openim::log::status "OpenIM Prometheus ports: ${MSG_GATEWAY_PROM_PORTS[*]}" -openim::log::status "OpenIM Msggateway config path: ${OPENIM_MSGGATEWAY_CONFIG}" + openim::log::status "OpenIM Msggateway config path: ${OPENIM_MSGGATEWAY_CONFIG}" -if [ ${#OPENIM_RPC_PORTS[@]} -ne ${#OPENIM_WS_PORTS[@]} ]; then - openim::log::error "ws_ports does not match push_rpc_ports or prome_ports in quantity!!!" - exit 1 -fi + if [ ${#OPENIM_RPC_PORTS[@]} -ne ${#OPENIM_WS_PORTS[@]} ]; then + openim::log::error "ws_ports does not match push_rpc_ports or prome_ports in quantity!!!" + exit 1 + fi -for ((i = 0; i < ${#OPENIM_WS_PORTS[@]}; i++)); do - openim::log::info "start push process, port: ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]}, prometheus port: ${PUSH_MSGGATEWAY_PORTS_ARRAY[$i]}" - - PROMETHEUS_PORT_OPTION="" - if [[ -n "${MSG_GATEWAY_PROM_PORTS[$i]}" ]]; then - PROMETHEUS_PORT_OPTION="--prometheus_port ${MSG_GATEWAY_PROM_PORTS[$i]}" - fi + for ((i = 0; i < ${#OPENIM_WS_PORTS[@]}; i++)); do + openim::log::info "start push process, port: ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]}, prometheus port: ${PUSH_MSGGATEWAY_PORTS_ARRAY[$i]}" + + PROMETHEUS_PORT_OPTION="" + if [[ -n "${MSG_GATEWAY_PROM_PORTS[$i]}" ]]; then + PROMETHEUS_PORT_OPTION="--prometheus_port ${MSG_GATEWAY_PROM_PORTS[$i]}" + fi - nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_RPC_PORTS[$i]} --ws_port ${OPENIM_WS_PORTS[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2>&1 & -done - -openim::util::check_process_names ${SERVER_NAME} + nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_RPC_PORTS[$i]} --ws_port ${OPENIM_WS_PORTS[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2>&1 & + done + openim::util::check_process_names ${SERVER_NAME} +} ###################################### Linux Systemd ###################################### SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" @@ -134,6 +136,6 @@ function openim::msggateway::status() fi } -if [[ "$*" =~ ${SERVER_NAME}:: ]];then +if [[ "$*" =~ openim::msggateway:: ]];then eval $* fi diff --git a/scripts/install/openim-msgtransfer.sh b/scripts/install/openim-msgtransfer.sh index 170c88e01..2dbadb5b5 100755 --- a/scripts/install/openim-msgtransfer.sh +++ b/scripts/install/openim-msgtransfer.sh @@ -25,41 +25,43 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P) 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} +function openim::msgtransfer::start() +{ + openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}" + openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGTRANSFER_BINARY}" -# Message Transfer Prometheus port list -MSG_TRANSFER_PROM_PORTS=(openim::util::list-to-string ${MSG_TRANSFER_PROM_PORT} ) + openim::util::stop_services_with_name ${SERVER_NAME} -openim::log::status "OpenIM Prometheus ports: ${MSG_TRANSFER_PROM_PORTS[*]}" + # Message Transfer Prometheus port list + MSG_TRANSFER_PROM_PORTS=(openim::util::list-to-string ${MSG_TRANSFER_PROM_PORT} ) -openim::log::status "OpenIM Msggateway config path: ${OPENIM_MSGTRANSFER_CONFIG}" + openim::log::status "OpenIM Prometheus ports: ${MSG_TRANSFER_PROM_PORTS[*]}" -openim::log::info "openim maggateway num: ${OPENIM_MSGGATEWAY_NUM}" + openim::log::status "OpenIM Msggateway config path: ${OPENIM_MSGTRANSFER_CONFIG}" -if [ "${OPENIM_MSGGATEWAY_NUM}" -lt 1 ]; then - opeim::log::error_exit "OPENIM_MSGGATEWAY_NUM must be greater than 0" -fi + openim::log::info "openim maggateway num: ${OPENIM_MSGGATEWAY_NUM}" -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 + if [ "${OPENIM_MSGGATEWAY_NUM}" -lt 1 ]; then + opeim::log::error_exit "OPENIM_MSGGATEWAY_NUM must be greater than 0" + 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 + 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 - nohup ${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} >> ${LOG_FILE} 2>&1 & -done + 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 -openim::util::check_process_names ${SERVER_NAME} + 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" @@ -133,6 +135,6 @@ function openim::msgtransfer::status() fi } -if [[ "$*" =~ ${SERVER_NAME}:: ]];then +if [[ "$*" =~ openim::msgtransfer:: ]];then eval $* fi diff --git a/scripts/install/openim-push.sh b/scripts/install/openim-push.sh index 01e354870..3be01bfbb 100755 --- a/scripts/install/openim-push.sh +++ b/scripts/install/openim-push.sh @@ -49,30 +49,33 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P) SERVER_NAME="openim-push" -openim::log::status "Start OpenIM Push, binary root: ${SERVER_NAME}" -openim::log::info "Start OpenIM Push, path: ${OPENIM_PUSH_BINARY}" +function openim::push::start() +{ + openim::log::status "Start OpenIM Push, binary root: ${SERVER_NAME}" + openim::log::info "Start OpenIM Push, path: ${OPENIM_PUSH_BINARY}" -openim::util::stop_services_with_name ${SERVER_NAME} + 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::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[@]}" + openim::log::status "push port list: ${OPENIM_PUSH_PORTS_ARRAY[@]}" + openim::log::status "prometheus port list: ${PUSH_PROM_PORTS_ARRAY[@]}" -if [ ${#OPENIM_PUSH_PORTS_ARRAY[@]} -ne ${#PUSH_PROM_PORTS_ARRAY[@]} ]; then - openim::log::error_exit "The length of the two port lists is different!" -fi + if [ ${#OPENIM_PUSH_PORTS_ARRAY[@]} -ne ${#PUSH_PROM_PORTS_ARRAY[@]} ]; then + openim::log::error_exit "The length of the two port lists is different!" + fi -for (( i=0; i<${#OPENIM_PUSH_PORTS_ARRAY[@]}; i++ )); do - openim::log::info "start push process, port: ${OPENIM_PUSH_PORTS_ARRAY[$i]}, prometheus port: ${PUSH_PROM_PORTS_ARRAY[$i]}" - nohup ${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]} >> ${LOG_FILE} 2>&1 & -done + for (( i=0; i<${#OPENIM_PUSH_PORTS_ARRAY[@]}; i++ )); do + openim::log::info "start push process, port: ${OPENIM_PUSH_PORTS_ARRAY[$i]}, prometheus port: ${PUSH_PROM_PORTS_ARRAY[$i]}" + nohup ${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]} >> ${LOG_FILE} 2>&1 & + done -openim::util::check_process_names ${SERVER_NAME} + openim::util::check_process_names ${SERVER_NAME} +} ###################################### Linux Systemd ###################################### SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" @@ -145,6 +148,6 @@ function openim::push::status() fi } -if [[ "$*" =~ ${SERVER_NAME}:: ]];then +if [[ "$*" =~ openim::push:: ]];then eval $* fi \ No newline at end of file diff --git a/scripts/install/openim-rpc.sh b/scripts/install/openim-rpc.sh index 02838ec33..8bf204e83 100755 --- a/scripts/install/openim-rpc.sh +++ b/scripts/install/openim-rpc.sh @@ -77,22 +77,45 @@ IFS=" " read -ra OPENIM_RPC_PROM_PORT_TARGETS <<< "$(openim::rpc::prometheus_por readonly OPENIM_RPC_PROM_PORT_TARGETS readonly OPENIM_RPC_PROM_PORT_LISTARIES=("${OPENIM_RPC_PROM_PORT_TARGETS[@]##*/}") -echo "OPENIM_RPC_SERVICE_LISTARIES: ${OPENIM_RPC_SERVICE_LISTARIES[@]}" -echo "OPENIM_RPC_PROM_PORT_LISTARIES: ${OPENIM_RPC_PROM_PORT_LISTARIES[@]}" -echo "OPENIM_RPC_PORT_LISTARIES: ${OPENIM_RPC_PORT_LISTARIES[@]}" +function openim::rpc::start() +{ + echo "OPENIM_RPC_SERVICE_LISTARIES: ${OPENIM_RPC_SERVICE_LISTARIES[@]}" + echo "OPENIM_RPC_PROM_PORT_LISTARIES: ${OPENIM_RPC_PROM_PORT_LISTARIES[@]}" + echo "OPENIM_RPC_PORT_LISTARIES: ${OPENIM_RPC_PORT_LISTARIES[@]}" -openim::log::info "Starting ${SERVER_NAME} ..." + openim::log::info "Starting ${SERVER_NAME} ..." -printf "+------------------------+-------+-----------------+\n" -printf "| Service Name | Port | Prometheus Port |\n" -printf "+------------------------+-------+-----------------+\n" + printf "+------------------------+-------+-----------------+\n" + printf "| Service Name | Port | Prometheus Port |\n" + printf "+------------------------+-------+-----------------+\n" -length=${#OPENIM_RPC_SERVICE_LISTARIES[@]} + length=${#OPENIM_RPC_SERVICE_LISTARIES[@]} -for ((i=0; i<$length; i++)); do - printf "| %-22s | %-5s | %-15s |\n" "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_PORT_LISTARIES[$i]}" "${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}" - printf "+------------------------+-------+-----------------+\n" -done + for ((i=0; i<$length; i++)); do + printf "| %-22s | %-5s | %-15s |\n" "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_PORT_LISTARIES[$i]}" "${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}" + printf "+------------------------+-------+-----------------+\n" + done + + # start all rpc services + for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do + openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES[$i]} + openim::log::info "OpenIM ${OPENIM_RPC_SERVICE_LISTARIES[$i]} config path: ${OPENIM_RPC_CONFIG}" + + # Get the service and Prometheus ports. + OPENIM_RPC_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PORT_LISTARIES[$i]}) ) + OPENIM_RPC_PROM_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}) ) + + for ((j = 0; j < ${#OPENIM_RPC_SERVICE_PORTS[@]}; j++)); do + openim::log::info "Starting ${OPENIM_RPC_SERVICE_LISTARIES[$i]} service, port: ${OPENIM_RPC_SERVICE_PORTS[j]}, prometheus port: ${OPENIM_RPC_PROM_PORTS[j]}, binary root: ${OPENIM_OUTPUT_HOSTBIN}/${OPENIM_RPC_SERVICE_LISTARIES[$i]}" + openim::rpc::start_service "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_SERVICE_PORTS[j]}" "${OPENIM_RPC_PROM_PORTS[j]}" + sleep 1 + done + done + + openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]} + # openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]} + +} function openim::rpc::start_service() { local binary_name="$1" @@ -108,40 +131,27 @@ function openim::rpc::start_service() { nohup ${cmd} >> "${LOG_FILE}" 2>&1 & } -# start all rpc services -for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do - openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES[$i]} - openim::log::info "OpenIM ${OPENIM_RPC_SERVICE_LISTARIES[$i]} config path: ${OPENIM_RPC_CONFIG}" - - # Get the service and Prometheus ports. - OPENIM_RPC_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PORT_LISTARIES[$i]}) ) - OPENIM_RPC_PROM_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}) ) - - for ((j = 0; j < ${#OPENIM_RPC_SERVICE_PORTS[@]}; j++)); do - openim::log::info "Starting ${OPENIM_RPC_SERVICE_LISTARIES[$i]} service, port: ${OPENIM_RPC_SERVICE_PORTS[j]}, prometheus port: ${OPENIM_RPC_PROM_PORTS[j]}, binary root: ${OPENIM_OUTPUT_HOSTBIN}/${OPENIM_RPC_SERVICE_LISTARIES[$i]}" - openim::rpc::start_service "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_SERVICE_PORTS[j]}" "${OPENIM_RPC_PROM_PORTS[j]}" - sleep 1 - done -done - -openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]} -# openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]} - ###################################### Linux Systemd ###################################### SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" function openim::rpc::install() { - + openim::log::info "Installing ${SERVER_NAME} ..." } function openim::rpc::uninstall() { + openim::log::info "Uninstalling ${SERVER_NAME} ..." } function openim::rpc::status() { + openim::log::info "Checking ${SERVER_NAME} status ..." + + openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]} + # openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]} + openim::util::check_process_names ${SERVER_NAME} } -if [[ "$*" =~ ${SERVER_NAME}:: ]];then +if [[ "$*" =~ openim::rpc:: ]];then eval $* fi \ No newline at end of file diff --git a/scripts/start-all.sh b/scripts/start-all.sh index f29109f11..76637521d 100755 --- a/scripts/start-all.sh +++ b/scripts/start-all.sh @@ -36,12 +36,21 @@ openim::log::install_errexit # Function to execute the scripts. function execute_scripts() { for script_path in "${OPENIM_SERVER_SCRIPT_START_LIST[@]}"; do + # Extract the script name without extension for argument generation. + script_name_with_prefix=$(basename "$script_path" .sh) + + # Remove the "openim-" prefix. + script_name=${script_name_with_prefix#openim-} + + # Construct the argument based on the script name. + arg="openim::${script_name}::start" + # Check if the script file exists and is executable. if [[ -x "$script_path" ]]; then openim::log::status "Starting script: ${script_path##*/}" # Log the script name. - - # Execute the script. - "$script_path" + + # Execute the script with the constructed argument. + "$script_path" "$arg" # Check if the script executed successfully. if [[ $? -eq 0 ]]; then diff --git a/scripts/update-generated-docs.sh b/scripts/update-generated-docs.sh new file mode 100644 index 000000000..6c35cff4b --- /dev/null +++ b/scripts/update-generated-docs.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# This file is not intended to be run automatically. It is meant to be run +# immediately before exporting docs. We do not want to check these documents in +# by default. + +set -o errexit +set -o nounset +set -o pipefail + +OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +source "${OPENIM_ROOT}/hack/lib/init.sh" + +openim::golang::setup_env + +BINS=( + cmd/gendocs + cmd/genopenimdocs + cmd/genman + cmd/genyaml +) +make -C "${OPENIM_ROOT}" WHAT="${BINS[*]}" + +openim::util::ensure-temp-dir + +openim::util::gen-docs "${OPENIM_TEMP}" + +# remove all of the old docs +openim::util::remove-gen-docs + +# Copy fresh docs into the repo. +# the shopt is so that we get docs/.generated_docs from the glob. +shopt -s dotglob +cp -af "${OPENIM_TEMP}"/* "${OPENIM_ROOT}" +shopt -u dotglob