mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 11:52:10 +08:00
Script Refactoring
This commit is contained in:
parent
99870c0839
commit
7dbb3116d9
@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -17,5 +19,39 @@ func main() {
|
||||
// Print the values of the flags
|
||||
fmt.Printf("args: -i %d -c %s\n", *index, *config)
|
||||
|
||||
time.Sleep(600 * time.Second)
|
||||
// Initialize the random number generator
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
// Randomly select two ports between 10000 and 20000
|
||||
port1 := rand.Intn(10001) + 10000 // This generates a number between 0-10000, then adds 10000
|
||||
port2 := rand.Intn(10001) + 10000
|
||||
|
||||
// Ensure port2 is different from port1
|
||||
for port2 == port1 {
|
||||
port2 = rand.Intn(10001) + 10000
|
||||
}
|
||||
|
||||
// Print the selected ports
|
||||
fmt.Printf("Randomly selected TCP ports to listen on: %d, %d\n", port1, port2)
|
||||
|
||||
// Function to start a TCP listener on a specified port
|
||||
startListener := func(port int) {
|
||||
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
||||
if err != nil {
|
||||
fmt.Printf("Error starting TCP listener on port %d: %v\n", port, err)
|
||||
return
|
||||
}
|
||||
defer listener.Close()
|
||||
fmt.Printf("Listening on port %d...\n", port)
|
||||
|
||||
// Here we simply keep the listener running. In a real application, you would accept connections.
|
||||
select {} // Block forever
|
||||
}
|
||||
|
||||
// Start TCP listeners on the selected ports
|
||||
go startListener(port1)
|
||||
go startListener(port2)
|
||||
|
||||
// Block forever
|
||||
select {}
|
||||
}
|
||||
|
||||
@ -44,3 +44,11 @@ for binary in "${!binaries[@]}"; do
|
||||
done
|
||||
|
||||
|
||||
for binary in "${!binaries[@]}"; do
|
||||
expected_count=${binaries[$binary]}
|
||||
full_path=$(get_bin_full_path "$binary")
|
||||
check_binary "$full_path"
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
@ -2831,9 +2831,53 @@ function openim::util::find_ports_for_all_services() {
|
||||
}
|
||||
|
||||
|
||||
check_binary_ports() {
|
||||
binary_path="$1"
|
||||
binary_name=$(basename "$binary_path")
|
||||
|
||||
# Check if the binary is running
|
||||
if pgrep -f "$binary_path" > /dev/null; then
|
||||
echo "$binary_name is running."
|
||||
|
||||
# Find the PID(s) of the running binary
|
||||
pids=$(pgrep -f "$binary_path")
|
||||
|
||||
# Initialize an empty string to store ports
|
||||
ports=""
|
||||
|
||||
# Loop through each PID
|
||||
for pid in $pids; do
|
||||
# Check for listening ports using lsof
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Linux
|
||||
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | cut -d':' -f2 | uniq)
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | awk -F'[:\.]+' '{print $(NF-1)}' | uniq)
|
||||
fi
|
||||
done
|
||||
|
||||
# Remove duplicate ports if any
|
||||
ports=$(echo "$ports" | uniq)
|
||||
|
||||
if [ -z "$ports" ]; then
|
||||
echo "$binary_name is not listening on any ports."
|
||||
else
|
||||
echo "$binary_name is listening on the following ports: $ports"
|
||||
fi
|
||||
else
|
||||
echo "$binary_name is not running."
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if [[ "$*" =~ openim::util:: ]];then
|
||||
eval $*
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
@ -14,7 +14,6 @@ source "$OPENIM_SCRIPTS/define/binaries.sh"
|
||||
# Main function to start binaries
|
||||
start_binaries() {
|
||||
local project_dir="$OPENIM_ROOT" # You should adjust this path as necessary
|
||||
echo $OPENIM_ROOT 12322222222222222222222222222222
|
||||
# Iterate over binaries defined in binary_path.sh
|
||||
for binary in "${!binaries[@]}"; do
|
||||
local count=${binaries[$binary]}
|
||||
@ -27,6 +26,8 @@ start_binaries() {
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Call the main function
|
||||
start_binaries
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user