feat: add more scrips

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

@ -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. 12. **openim-rpc-third:** Script dedicated to third-party integrations with OpenIM RPC.
13. **openim-rpc-user:** Control interface for OpenIM RPC User operations. 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. 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). 2. **Function-based Execution:** Invoking specific functions within the script for more specialized operations (e.g., install, uninstall).
```bash ```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 ### 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. 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.

@ -13,11 +13,43 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # 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) OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh [[ -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-msggateway.sh
source ${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh source ${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh
source ${OPENIM_ROOT}/scripts/install/openim-push.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 source ${OPENIM_ROOT}/scripts/install/man.sh
# Detailed help function # Detailed help function
function show_help() { function openim::install::show_help() {
echo "OpenIM Installer" echo "OpenIM Installer"
echo "Usage: $0 <command> [options]" echo "Usage: $0 <command> [options]"
echo "" echo ""
@ -86,6 +118,12 @@ function openim::install::status()
openim::log::success "openim status success" 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 # Argument parsing to call functions based on user input
while (( "$#" )); do while (( "$#" )); do
case "$1" in case "$1" in
@ -102,14 +140,8 @@ while (( "$#" )); do
shift shift
;; ;;
-h|--help|*) -h|--help|*)
show_help openim::install::show_help
exit 0 exit 0
;; ;;
esac esac
done done
# If no arguments are provided, show help
if [[ $# -eq 0 ]]; then
show_help
exit 0
fi

@ -33,6 +33,8 @@ readonly OPENIM_API_SERVICE_TARGETS=(
) )
readonly OPENIM_API_SERVICE_LISTARIES=("${OPENIM_API_SERVICE_TARGETS[@]##*/}") readonly OPENIM_API_SERVICE_LISTARIES=("${OPENIM_API_SERVICE_TARGETS[@]##*/}")
function openim::api::start()
{
echo "++ OPENIM_API_SERVICE_LISTARIES: ${OPENIM_API_SERVICE_LISTARIES[@]}" echo "++ OPENIM_API_SERVICE_LISTARIES: ${OPENIM_API_SERVICE_LISTARIES[@]}"
echo "++ OPENIM_API_PORT_LISTARIES: ${OPENIM_API_PORT_LISTARIES[@]}" echo "++ OPENIM_API_PORT_LISTARIES: ${OPENIM_API_PORT_LISTARIES[@]}"
echo "++ OpenIM API config path: ${OPENIM_API_CONFIG}" echo "++ OpenIM API config path: ${OPENIM_API_CONFIG}"
@ -49,21 +51,6 @@ for ((i=0; i<$length; i++)); do
printf "| %-22s | %6s |\n" "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}" printf "| %-22s | %6s |\n" "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}"
printf "+------------------------+--------------+\n" printf "+------------------------+--------------+\n"
done done
function openim::api::start_service() {
local binary_name="$1"
local service_port="$2"
local prometheus_port="$3"
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_API_CONFIG}"
nohup ${cmd} >> "${LOG_FILE}" 2>&1 &
if [ $? -ne 0 ]; then
openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}."
fi
}
# start all api services # start all api services
for ((i = 0; i < ${#OPENIM_API_SERVICE_LISTARIES[*]}; i++)); do for ((i = 0; i < ${#OPENIM_API_SERVICE_LISTARIES[*]}; i++)); do
openim::util::stop_services_with_name ${OPENIM_API_SERVICE_LISTARIES[$i]} openim::util::stop_services_with_name ${OPENIM_API_SERVICE_LISTARIES[$i]}
@ -86,22 +73,40 @@ done
OPENIM_API_PORT_STRINGARIES=( $(openim::util::list-to-string ${OPENIM_API_PORT_LISTARIES[@]}) ) OPENIM_API_PORT_STRINGARIES=( $(openim::util::list-to-string ${OPENIM_API_PORT_LISTARIES[@]}) )
openim::util::check_ports ${OPENIM_API_PORT_STRINGARIES[@]} openim::util::check_ports ${OPENIM_API_PORT_STRINGARIES[@]}
}
function openim::api::start_service() {
local binary_name="$1"
local service_port="$2"
local prometheus_port="$3"
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_API_CONFIG}"
nohup ${cmd} >> "${LOG_FILE}" 2>&1 &
if [ $? -ne 0 ]; then
openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}."
fi
}
###################################### Linux Systemd ###################################### ###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
function openim::api::install() { function openim::api::install() {
openim::log::info "Installing ${SERVER_NAME} ..."
} }
function openim::api::uninstall() { function openim::api::uninstall() {
openim::log::info "Uninstalling ${SERVER_NAME} ..."
} }
function openim::api::status() { 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 $* eval $*
fi fi

@ -44,6 +44,8 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
SERVER_NAME="openim-crontask" SERVER_NAME="openim-crontask"
function openim::crontask::start()
{
openim::log::info "Start OpenIM Cron, binary root: ${SERVER_NAME}" openim::log::info "Start OpenIM Cron, binary root: ${SERVER_NAME}"
openim::log::status "Start OpenIM Cron, path: ${OPENIM_CRONTASK_BINARY}" openim::log::status "Start OpenIM Cron, path: ${OPENIM_CRONTASK_BINARY}"
@ -52,6 +54,7 @@ openim::util::stop_services_with_name ${SERVER_NAME}
openim::log::status "start cron_task process, path: ${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} >> ${LOG_FILE} 2>&1 &
openim::util::check_process_names ${SERVER_NAME} openim::util::check_process_names ${SERVER_NAME}
}
###################################### Linux Systemd ###################################### ###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
@ -125,6 +128,6 @@ function openim::crontask::status()
fi fi
} }
if [[ "$*" =~ ${SERVER_NAME}:: ]];then if [[ "$*" =~ openim::crontask:: ]];then
eval $* eval $*
fi fi

@ -25,6 +25,8 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
SERVER_NAME="openim-msggateway" SERVER_NAME="openim-msggateway"
function openim::msggateway::start()
{
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}" openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}" openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}"
@ -60,7 +62,7 @@ for ((i = 0; i < ${#OPENIM_WS_PORTS[@]}; i++)); do
done done
openim::util::check_process_names ${SERVER_NAME} openim::util::check_process_names ${SERVER_NAME}
}
###################################### Linux Systemd ###################################### ###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
@ -134,6 +136,6 @@ function openim::msggateway::status()
fi fi
} }
if [[ "$*" =~ ${SERVER_NAME}:: ]];then if [[ "$*" =~ openim::msggateway:: ]];then
eval $* eval $*
fi fi

@ -25,6 +25,8 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
SERVER_NAME="openim-msgtransfer" SERVER_NAME="openim-msgtransfer"
function openim::msgtransfer::start()
{
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}" openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGTRANSFER_BINARY}" openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGTRANSFER_BINARY}"
@ -59,7 +61,7 @@ for (( i=1; i<=$OPENIM_MSGGATEWAY_NUM; i++ )) do
done done
openim::util::check_process_names ${SERVER_NAME} openim::util::check_process_names ${SERVER_NAME}
}
###################################### Linux Systemd ###################################### ###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
@ -133,6 +135,6 @@ function openim::msgtransfer::status()
fi fi
} }
if [[ "$*" =~ ${SERVER_NAME}:: ]];then if [[ "$*" =~ openim::msgtransfer:: ]];then
eval $* eval $*
fi fi

@ -49,6 +49,8 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
SERVER_NAME="openim-push" SERVER_NAME="openim-push"
function openim::push::start()
{
openim::log::status "Start OpenIM Push, binary root: ${SERVER_NAME}" openim::log::status "Start OpenIM Push, binary root: ${SERVER_NAME}"
openim::log::info "Start OpenIM Push, path: ${OPENIM_PUSH_BINARY}" openim::log::info "Start OpenIM Push, path: ${OPENIM_PUSH_BINARY}"
@ -73,6 +75,7 @@ for (( i=0; i<${#OPENIM_PUSH_PORTS_ARRAY[@]}; i++ )); do
done done
openim::util::check_process_names ${SERVER_NAME} openim::util::check_process_names ${SERVER_NAME}
}
###################################### Linux Systemd ###################################### ###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
@ -145,6 +148,6 @@ function openim::push::status()
fi fi
} }
if [[ "$*" =~ ${SERVER_NAME}:: ]];then if [[ "$*" =~ openim::push:: ]];then
eval $* eval $*
fi fi

@ -77,6 +77,8 @@ IFS=" " read -ra OPENIM_RPC_PROM_PORT_TARGETS <<< "$(openim::rpc::prometheus_por
readonly OPENIM_RPC_PROM_PORT_TARGETS readonly OPENIM_RPC_PROM_PORT_TARGETS
readonly OPENIM_RPC_PROM_PORT_LISTARIES=("${OPENIM_RPC_PROM_PORT_TARGETS[@]##*/}") readonly OPENIM_RPC_PROM_PORT_LISTARIES=("${OPENIM_RPC_PROM_PORT_TARGETS[@]##*/}")
function openim::rpc::start()
{
echo "OPENIM_RPC_SERVICE_LISTARIES: ${OPENIM_RPC_SERVICE_LISTARIES[@]}" echo "OPENIM_RPC_SERVICE_LISTARIES: ${OPENIM_RPC_SERVICE_LISTARIES[@]}"
echo "OPENIM_RPC_PROM_PORT_LISTARIES: ${OPENIM_RPC_PROM_PORT_LISTARIES[@]}" echo "OPENIM_RPC_PROM_PORT_LISTARIES: ${OPENIM_RPC_PROM_PORT_LISTARIES[@]}"
echo "OPENIM_RPC_PORT_LISTARIES: ${OPENIM_RPC_PORT_LISTARIES[@]}" echo "OPENIM_RPC_PORT_LISTARIES: ${OPENIM_RPC_PORT_LISTARIES[@]}"
@ -94,20 +96,6 @@ for ((i=0; i<$length; i++)); do
printf "+------------------------+-------+-----------------+\n" printf "+------------------------+-------+-----------------+\n"
done done
function openim::rpc::start_service() {
local binary_name="$1"
local service_port="$2"
local prometheus_port="$3"
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_RPC_CONFIG}"
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 &
}
# start all rpc services # start all rpc services
for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do
openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES[$i]} openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES[$i]}
@ -127,21 +115,43 @@ done
openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]} openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]}
# openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]} # openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]}
}
function openim::rpc::start_service() {
local binary_name="$1"
local service_port="$2"
local prometheus_port="$3"
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_RPC_CONFIG}"
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 &
}
###################################### Linux Systemd ###################################### ###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
function openim::rpc::install() { function openim::rpc::install() {
openim::log::info "Installing ${SERVER_NAME} ..."
} }
function openim::rpc::uninstall() { function openim::rpc::uninstall() {
openim::log::info "Uninstalling ${SERVER_NAME} ..."
} }
function openim::rpc::status() { 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 $* eval $*
fi fi

@ -36,12 +36,21 @@ openim::log::install_errexit
# Function to execute the scripts. # Function to execute the scripts.
function execute_scripts() { function execute_scripts() {
for script_path in "${OPENIM_SERVER_SCRIPT_START_LIST[@]}"; do 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. # Check if the script file exists and is executable.
if [[ -x "$script_path" ]]; then if [[ -x "$script_path" ]]; then
openim::log::status "Starting script: ${script_path##*/}" # Log the script name. openim::log::status "Starting script: ${script_path##*/}" # Log the script name.
# Execute the script. # Execute the script with the constructed argument.
"$script_path" "$script_path" "$arg"
# Check if the script executed successfully. # Check if the script executed successfully.
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then

@ -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
Loading…
Cancel
Save