feat: add openim deployment tactics

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
pull/1890/head
Xinwei Xiong (cubxxw) 2 years ago
parent 6c7b94f03f
commit 40b1664dd2

@ -15,8 +15,6 @@
package cmd
import (
"fmt"
"github.com/OpenIMSDK/protocol/constant"
"github.com/spf13/cobra"
@ -41,7 +39,6 @@ func (a *ApiCmd) AddApi(f func(port int, promPort int) error) {
}
func (a *ApiCmd) GetPortFromConfig(portType string) int {
fmt.Println("GetPortFromConfig:", portType)
if portType == constant.FlagPort {
return config2.Config.Api.OpenImApiPort[0]
} else if portType == constant.FlagPrometheusPort {

@ -47,7 +47,6 @@ func (m *MsgTransferCmd) Exec() error {
}
func (m *MsgTransferCmd) GetPortFromConfig(portType string) int {
fmt.Println("GetPortFromConfig:", portType)
if portType == constant.FlagPort {
return 0
} else if portType == constant.FlagPrometheusPort {
@ -56,9 +55,11 @@ func (m *MsgTransferCmd) GetPortFromConfig(portType string) int {
}
return 0
}
func (m *MsgTransferCmd) AddTransferProgressFlag() {
m.Command.Flags().IntP(constant.FlagTransferProgressIndex, "n", 0, "transfer progress index")
}
func (m *MsgTransferCmd) getTransferProgressFlagValue() int {
nindex, err := m.Command.Flags().GetInt(constant.FlagTransferProgressIndex)
if err != nil {

@ -163,7 +163,7 @@ func (r *RootCmd) GetPrometheusPortFlag() int {
func (r *RootCmd) getConfFromCmdAndInit(cmdLines *cobra.Command) error {
configFolderPath, _ := cmdLines.Flags().GetString(constant.FlagConf)
fmt.Println("configFolderPath:", configFolderPath)
fmt.Println("The directory of the configuration file to start the process:", configFolderPath)
return config2.InitConfig(configFolderPath)
}
@ -176,10 +176,9 @@ func (r *RootCmd) AddCommand(cmds ...*cobra.Command) {
}
func (r *RootCmd) GetPortFromConfig(portType string) int {
fmt.Println("RootCmd.GetPortFromConfig:", portType)
return 0
}
func (r *RootCmd) PortFromConfig(portType string) int {
fmt.Println("PortFromConfig:", portType)
return r.cmdItf.GetPortFromConfig(portType)
}

@ -101,7 +101,7 @@ func initConfig(config any, configName, configFolderPath string) error {
if err = yaml.Unmarshal(data, config); err != nil {
return fmt.Errorf("unmarshal yaml error: %w", err)
}
fmt.Println("use config", configFolderPath)
fmt.Println("The path of the configuration file to start the process:", configFolderPath)
return nil
}

@ -33,8 +33,12 @@ readonly OPENIM_API_SERVICE_TARGETS=(
)
readonly OPENIM_API_SERVICE_LISTARIES=("${OPENIM_API_SERVICE_TARGETS[@]##*/}")
function openim::api::start() {
readonly OPENIM_API_PROMETHEUS_PORT_TARGETS=(
${API_PROM_PORT}
)
readonly OPENIM_API_PROMETHEUS_PORT_LISTARIES=("${OPENIM_API_PROMETHEUS_PORT_TARGETS[@]##*/}")
function openim::api::start() {
rm -rf "$TMP_LOG_FILE"
echo "++ OPENIM_API_SERVICE_LISTARIES: ${OPENIM_API_SERVICE_LISTARIES[@]}"
@ -47,34 +51,20 @@ function openim::api::start() {
printf "| Service Name | Port |\n"
printf "+------------------------+--------------+\n"
length=${#OPENIM_API_SERVICE_LISTARIES[@]}
local length=${#OPENIM_API_SERVICE_LISTARIES[@]}
for ((i=0; i<$length; i++)); do
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_on_ports ${OPENIM_API_PORT_LISTARIES[$i]}
# Stop services on the specified ports before starting new ones
openim::util::stop_services_on_ports "${OPENIM_API_PORT_LISTARIES[$i]}"
openim::util::stop_services_on_ports "${OPENIM_API_PROMETHEUS_PORT_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]}"
# Start the service with Prometheus port if specified
openim::api::start_service "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}" "${OPENIM_API_PROMETHEUS_PORT_LISTARIES[$i]}"
sleep 2
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() {
@ -83,7 +73,15 @@ function openim::api::start_service() {
local prometheus_port="$3"
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_API_CONFIG}"
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
# Append Prometheus port argument if specified
if [ -n "${prometheus_port}" ]; then
cmd+=" --prometheus_port ${prometheus_port}"
fi
echo "Starting service with command: $cmd"
nohup $cmd >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
if [ $? -ne 0 ]; then
openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}."

@ -54,7 +54,7 @@ function openim::crontask::start() {
openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}"
nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
openim::util::check_process_names ${SERVER_NAME}
}

@ -64,7 +64,7 @@ function openim::msggateway::start() {
PROMETHEUS_PORT_OPTION="--prometheus_port ${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}"
fi
nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
done
openim::util::check_process_names ${SERVER_NAME}

@ -59,7 +59,7 @@ function openim::msgtransfer::start() {
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} -n ${i} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
nohup ${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} -n ${i} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
done
openim::util::check_process_names "${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME}"

@ -73,7 +73,7 @@ function openim::push::start() {
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]} -c ${OPENIM_PUSH_CONFIG} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]} >${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
nohup ${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} -c ${OPENIM_PUSH_CONFIG} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]} >${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
done
openim::util::check_process_names ${SERVER_NAME}

@ -160,7 +160,7 @@ function openim::rpc::start_service() {
printf "Specifying prometheus port: %s\n" "${prometheus_port}"
cmd="${cmd} --prometheus_port ${prometheus_port}"
fi
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
}
###################################### Linux Systemd ######################################

@ -486,7 +486,7 @@ openim::util::stop_services_on_ports() {
local pid=$(echo $line | awk '{print $2}')
# Try to stop the service by killing its process.
if kill -10 $pid; then
if kill -9 $pid; then
stopped+=($port)
else
not_stopped+=($port)
@ -505,8 +505,6 @@ openim::util::stop_services_on_ports() {
# Print information about ports whose processes were successfully stopped.
if [[ ${#stopped[@]} -ne 0 ]]; then
echo
openim::log::info "Stopped services on ports:"
for port in "${stopped[@]}"; do
openim::log::info "Successfully stopped service on port $port."
done
@ -563,7 +561,7 @@ openim::util::stop_services_with_name() {
# If there's a Process ID, it means the service with the name is running.
if [[ -n $pid ]]; then
# Try to stop the service by killing its process.
if kill -10 $pid 2>/dev/null; then
if kill -9 $pid 2>/dev/null; then
stopped_this_time=true
fi
fi
@ -1722,7 +1720,7 @@ openim::util::stop_services_on_ports() {
local pid=$(echo $line | awk '{print $2}')
# Try to stop the service by killing its process.
if kill -10 $pid; then
if kill -9 $pid; then
stopped+=($port)
else
not_stopped+=($port)
@ -1741,8 +1739,6 @@ openim::util::stop_services_on_ports() {
# Print information about ports whose processes were successfully stopped.
if [[ ${#stopped[@]} -ne 0 ]]; then
echo
openim::log::info "Stopped services on ports:"
for port in "${stopped[@]}"; do
openim::log::info "Successfully stopped service on port $port."
done
@ -1799,7 +1795,7 @@ openim::util::stop_services_with_name() {
# If there's a Process ID, it means the service with the name is running.
if [[ -n $pid ]]; then
# Try to stop the service by killing its process.
if kill -10 $pid 2>/dev/null; then
if kill -9 $pid 2>/dev/null; then
stopped_this_time=true
fi
fi
@ -2574,6 +2570,7 @@ function openim::util::gencpu() {
echo $cpu_count
}
function openim::util::set_max_fd() {
local desired_fd=$1
local max_fd_limit
@ -2754,38 +2751,6 @@ function openim::util::gencpu() {
echo $cpu_count
}
function openim::util::set_max_fd() {
local desired_fd=$1
local max_fd_limit
# Check if we're not on cygwin or darwin.
if [ "$(uname -s | tr '[:upper:]' '[:lower:]')" != "cygwin" ] && [ "$(uname -s | tr '[:upper:]' '[:lower:]')" != "darwin" ]; then
# Try to get the hard limit.
max_fd_limit=$(ulimit -H -n)
if [ $? -eq 0 ]; then
# If desired_fd is 'maximum' or 'max', set it to the hard limit.
if [ "$desired_fd" = "maximum" ] || [ "$desired_fd" = "max" ]; then
desired_fd="$max_fd_limit"
fi
# Check if desired_fd is less than or equal to max_fd_limit.
if [ "$desired_fd" -le "$max_fd_limit" ]; then
ulimit -n "$desired_fd"
if [ $? -ne 0 ]; then
echo "Warning: Could not set maximum file descriptor limit to $desired_fd"
fi
else
echo "Warning: Desired file descriptor limit ($desired_fd) is greater than the hard limit ($max_fd_limit)"
fi
else
echo "Warning: Could not query the maximum file descriptor hard limit."
fi
else
echo "Warning: Not attempting to modify file descriptor limit on Cygwin or Darwin."
fi
}
function openim::util::gen_os_arch() {
# Get the current operating system and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')

@ -36,11 +36,4 @@ echo -e "\n++ Stop all processes in the path ${OPENIM_OUTPUT_HOSTBIN}"
openim::util::stop_services_with_name "${OPENIM_OUTPUT_HOSTBIN}"
echo -n "Stopping services 15 seconds."
for i in {1..15}; do
echo -n "."
sleep 1
done
echo -e "\nServices stopped."
openim::log::success "✨ Wait 15 seconds for all processes to be killed"
openim::log::success "✨ All processes to be killed"
Loading…
Cancel
Save