mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-10-29 15:30:03 +08:00
feat: add more scrips
Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
parent
f0ad869d29
commit
d3364e374f
@ -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.
|
||||
|
||||
@ -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 <command> [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
|
||||
@ -33,6 +33,8 @@ readonly 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_PORT_LISTARIES: ${OPENIM_API_PORT_LISTARIES[@]}"
|
||||
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 "+------------------------+--------------+\n"
|
||||
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
|
||||
for ((i = 0; i < ${#OPENIM_API_SERVICE_LISTARIES[*]}; i++)); do
|
||||
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::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 ######################################
|
||||
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
|
||||
@ -44,6 +44,8 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
|
||||
SERVER_NAME="openim-crontask"
|
||||
|
||||
function openim::crontask::start()
|
||||
{
|
||||
openim::log::info "Start OpenIM Cron, binary root: ${SERVER_NAME}"
|
||||
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}"
|
||||
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
|
||||
|
||||
@ -25,6 +25,8 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
|
||||
SERVER_NAME="openim-msggateway"
|
||||
|
||||
function openim::msggateway::start()
|
||||
{
|
||||
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
|
||||
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}"
|
||||
|
||||
@ -60,7 +62,7 @@ for ((i = 0; i < ${#OPENIM_WS_PORTS[@]}; i++)); do
|
||||
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
|
||||
|
||||
@ -25,6 +25,8 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
|
||||
SERVER_NAME="openim-msgtransfer"
|
||||
|
||||
function openim::msgtransfer::start()
|
||||
{
|
||||
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
|
||||
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGTRANSFER_BINARY}"
|
||||
|
||||
@ -59,7 +61,7 @@ for (( i=1; i<=$OPENIM_MSGGATEWAY_NUM; i++ )) do
|
||||
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
|
||||
|
||||
@ -49,6 +49,8 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
|
||||
SERVER_NAME="openim-push"
|
||||
|
||||
function openim::push::start()
|
||||
{
|
||||
openim::log::status "Start OpenIM Push, binary root: ${SERVER_NAME}"
|
||||
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
|
||||
|
||||
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
|
||||
@ -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_LISTARIES=("${OPENIM_RPC_PROM_PORT_TARGETS[@]##*/}")
|
||||
|
||||
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[@]}"
|
||||
@ -94,20 +96,6 @@ for ((i=0; i<$length; i++)); do
|
||||
printf "+------------------------+-------+-----------------+\n"
|
||||
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
|
||||
for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do
|
||||
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_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 ######################################
|
||||
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
|
||||
@ -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
|
||||
|
||||
35
scripts/update-generated-docs.sh
Normal file
35
scripts/update-generated-docs.sh
Normal file
@ -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…
x
Reference in New Issue
Block a user