diff --git a/docker-compose.yaml b/docker-compose.yaml index 478a8c349..0df119260 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -103,6 +103,9 @@ services: # image: registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server:main # image: openim/openim-server:main container_name: openim-server + ports: + - 10001:10001 + - 10002:10002 healthcheck: test: ["CMD-SHELL", "./scripts/check-all.sh"] interval: 30s diff --git a/scripts/docker-start-all.sh b/scripts/docker-start-all.sh index 9cfd88324..8344ec239 100755 --- a/scripts/docker-start-all.sh +++ b/scripts/docker-start-all.sh @@ -27,6 +27,9 @@ source "${OPENIM_ROOT}/scripts/install/common.sh" trap 'openim::util::onCtrlC' INT "${OPENIM_ROOT}"/scripts/start-all.sh + +sleep 5 + "${OPENIM_ROOT}"/scripts/check-all.sh tail -f ${LOG_FILE} \ No newline at end of file diff --git a/scripts/install/openim-rpc.sh b/scripts/install/openim-rpc.sh index d66793b7e..6199ee5f4 100755 --- a/scripts/install/openim-rpc.sh +++ b/scripts/install/openim-rpc.sh @@ -135,10 +135,11 @@ function openim::rpc::start() { for ((j = 0; j < ${#OPENIM_RPC_SERVICE_PORTS_ARRAY[@]}; 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 0.5 done done + sleep 0.5 + openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]} # openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]} diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 4359f6066..392dfa45e 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -267,22 +267,26 @@ openim::util::check_ports() { openim::log::info "Checking ports: $*" # Iterate over each given port. for port in "$@"; do - # Use the `lsof` command to find process information related to the given port. - local info=$(lsof -i :$port -n -P | grep LISTEN || true) + # Use the `ss` command to find process information related to the given port. + local info=$(ss -ltnp | grep -w ":$port" || true) # If there's no process information, it means the process associated with the port is not running. if [[ -z $info ]]; then not_started+=($port) else - # If there's process information, extract relevant details: - # Process ID, Command Name, and Start Time. - local pid=$(echo $info | awk '{print $2}') - local command=$(echo $info | awk '{print $1}') - local start_time=$(ps -o lstart= -p $pid) - started+=("Port $port - Command: $command, PID: $pid, Start time: $start_time") + # Extract relevant details: Process Name, PID, and FD. + local details=$(echo $info | sed -n 's/.*users:(("\([^"]*\)",pid=\([^,]*\),fd=\([^)]*\))).*/\1 \2 \3/p') + local command=$(echo $details | awk '{print $1}') + local pid=$(echo $details | awk '{print $2}') + local fd=$(echo $details | awk '{print $3}') + + # Get the start time of the process using the PID + local start_time=$(ps -p $pid -o lstart=) + + started+=("Port $port - Command: $command, PID: $pid, FD: $fd, Started: $start_time") fi done - echo + # Print information about ports whose processes are not running. if [[ ${#not_started[@]} -ne 0 ]]; then openim::log::info "### Not started ports:" @@ -293,7 +297,6 @@ openim::util::check_ports() { # Print information about ports whose processes are running. if [[ ${#started[@]} -ne 0 ]]; then - echo openim::log::info "### Started ports:" for info in "${started[@]}"; do openim::log::info "$info" @@ -305,11 +308,14 @@ openim::util::check_ports() { echo "++++ OpenIM Log >> cat ${LOG_FILE}" return 1 else - openim::log::success "started[@] processes are running." + openim::log::success "All specified processes are running." return 0 fi } -# openim::util::check_ports 10002 1004 +# set +o errexit +# Sample call for testing: +# openim::util::check_ports 10002 1004 12345 13306 +# set -o errexit # The `openim::util::check_process_names` function analyzes the state of processes based on given names. # It accepts multiple process names as arguments and prints: diff --git a/scripts/start-all.sh b/scripts/start-all.sh index f75c92505..418cab97c 100755 --- a/scripts/start-all.sh +++ b/scripts/start-all.sh @@ -62,9 +62,9 @@ function execute_scripts() { openim::log::errexit "Script ${script_path##*/} is missing or not executable." fi done + sleep 0.5 } -sleep 0.5 # TODO Prelaunch tools, simple for now, can abstract functions later TOOLS_START_SCRIPTS_PATH=${START_SCRIPTS_PATH}/openim-tools.sh