diff --git a/pkg/common/cmd/api.go b/pkg/common/cmd/api.go index 00c6cb241..db1f488ad 100644 --- a/pkg/common/cmd/api.go +++ b/pkg/common/cmd/api.go @@ -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 { diff --git a/pkg/common/cmd/msg_transfer.go b/pkg/common/cmd/msg_transfer.go index f99b625c7..e57bab89d 100644 --- a/pkg/common/cmd/msg_transfer.go +++ b/pkg/common/cmd/msg_transfer.go @@ -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 { diff --git a/pkg/common/cmd/root.go b/pkg/common/cmd/root.go index 98ca8f892..eab4a32bc 100644 --- a/pkg/common/cmd/root.go +++ b/pkg/common/cmd/root.go @@ -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) } diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index 64719d6a1..4037429e3 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -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 } diff --git a/scripts/install/openim-api.sh b/scripts/install/openim-api.sh index c81dfcd0d..be2a2d33b 100755 --- a/scripts/install/openim-api.sh +++ b/scripts/install/openim-api.sh @@ -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> "${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}." diff --git a/scripts/install/openim-crontask.sh b/scripts/install/openim-crontask.sh index 6068e97d5..395b27cd1 100755 --- a/scripts/install/openim-crontask.sh +++ b/scripts/install/openim-crontask.sh @@ -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} } diff --git a/scripts/install/openim-msggateway.sh b/scripts/install/openim-msggateway.sh index 4e591deca..a2316c784 100755 --- a/scripts/install/openim-msggateway.sh +++ b/scripts/install/openim-msggateway.sh @@ -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} diff --git a/scripts/install/openim-msgtransfer.sh b/scripts/install/openim-msgtransfer.sh index def22c38b..c24ed96fb 100755 --- a/scripts/install/openim-msgtransfer.sh +++ b/scripts/install/openim-msgtransfer.sh @@ -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}" diff --git a/scripts/install/openim-push.sh b/scripts/install/openim-push.sh index 4d14ca675..ab12735c1 100755 --- a/scripts/install/openim-push.sh +++ b/scripts/install/openim-push.sh @@ -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} diff --git a/scripts/install/openim-rpc.sh b/scripts/install/openim-rpc.sh index 00031f211..f8feaaa57 100755 --- a/scripts/install/openim-rpc.sh +++ b/scripts/install/openim-rpc.sh @@ -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 ###################################### diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index cace53645..18be305cd 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -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:]') diff --git a/scripts/stop-all.sh b/scripts/stop-all.sh index 1d2eddd78..2acb9cdc5 100755 --- a/scripts/stop-all.sh +++ b/scripts/stop-all.sh @@ -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" \ No newline at end of file +openim::log::success "✨ All processes to be killed" \ No newline at end of file