diff --git a/scripts-new/bricks.sh b/scripts-new/bricks.sh new file mode 100644 index 000000000..efdb3321b --- /dev/null +++ b/scripts-new/bricks.sh @@ -0,0 +1,104 @@ + +OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/ +source "${OPENIM_ROOT}/lib/util.sh" +source "${OPENIM_ROOT}/define/binaries.sh" +source "${OPENIM_ROOT}/lib/path.sh" + + + +#停止所有的二进制对应的进程 +stop_binaries{ + for binary in "${!binaries[@]}"; do + full_path=$(get_bin_full_path "$binary") + openim::util::kill_exist_binary "$full_path" + done +} + + +#启动所有的二进制 +start_binaries() { + local project_dir="$OPENIM_ROOT" # You should adjust this path as necessary + # Iterate over binaries defined in binary_path.sh + for binary in "${!binaries[@]}"; do + local count=${binaries[$binary]} + local bin_full_path=$(get_bin_full_path "$binary") + # Loop to start binary the specified number of times + for ((i=0; i "test.log" 2>&1 & + + done + done +} + + +#kill二进制全路径对应的进程 +kill_exist_binaries(){ + for binary in "${!binaries[@]}"; do + full_path=$(get_bin_full_path "$binary") + result=$(openim::util::kill_exist_binary "$full_path" | tail -n1) + if [ "$result" -eq 0 ]; then + else + echo "$full_path running. waiting stop" + fi + done +} + + +#检查所有的二进制是否退出 +check_binaries_stop() { + local running_binaries=0 + + for binary in "${!binaries[@]}"; do + full_path=$(get_bin_full_path "$binary") + + result=$(openim::util::check_process_names_exist "$full_path") + if [ "$result" -ne 0 ]; then + echo "Process for $binary is still running." + running_binaries=$((running_binaries + 1)) + fi + done + + if [ "$running_binaries" -ne 0 ]; then + echo "There are $running_binaries binaries still running. Aborting..." + return 1 + else + echo "All processes have been stopped." + return 0 + fi +} + + + +#检查所有的二进制是否运行 +check_binaries_running{ + for binary in "${!binaries[@]}"; do + expected_count=${binaries[$binary]} + full_path=$(get_bin_full_path "$binary") + + result=$(openim::util::check_process_names "$full_path" "$expected_count") + if [ "$result" -eq 0 ]; then + echo "$binary is running normally." + return 0 + else + echo "$binary is not running normally, $result processes missing." + return 1 + fi + done +} + + + + +#打印所有的二进制对应的进程所所监听的端口 +print_listened_ports_by_binaries{ + for binary in "${!binaries[@]}"; do + expected_count=${binaries[$binary]} + base_path=$(get_bin_full_path "$binary") + for ((i=0; i/dev/null; then - stopped_this_time=true - fi - fi - done - - if $stopped_this_time; then - stopped+=("$server_name") - else - not_stopped+=("$server_name") - fi - done - return 0 - -} # sleep 333333& # sleep 444444& # ps -ef | grep "sleep" @@ -2845,7 +2747,8 @@ function openim::util::find_ports_for_all_services() { } -check_binary_ports() { + +function openim::util::print_binary_ports() { binary_path="$1" # Check if the binary is running @@ -2886,21 +2789,6 @@ check_binary_ports() { } -kill_binary() { - binary_path="$1" - - pids=$(pgrep -f "$binary_path") - - if [ -z "$pids" ]; then - echo "No process found for $binary_path" - else - for pid in $pids; do - echo "Killing process $pid associated with $binary_path" - kill -9 "$pid" - done - fi -} - function openim::util::kill_exist_binary() { local binary_path="$1" diff --git a/scripts-new/start.sh b/scripts-new/start.sh index 76a4f08e2..92f86c91d 100644 --- a/scripts-new/start.sh +++ b/scripts-new/start.sh @@ -12,57 +12,29 @@ source "$OPENIM_SCRIPTS/define/binaries.sh" # If not, you'll need to define it to return the appropriate platform directory name. # Main function to start binaries -start_binaries() { - local project_dir="$OPENIM_ROOT" # You should adjust this path as necessary - # Iterate over binaries defined in binary_path.sh - for binary in "${!binaries[@]}"; do - local count=${binaries[$binary]} - local bin_full_path=$(get_bin_full_path "$binary") - # Loop to start binary the specified number of times - for ((i=0; i "test.log" 2>&1 & - - done - done -} - -kill_exist_binaries(){ - for binary in "${!binaries[@]}"; do - full_path=$(get_bin_full_path "$binary") - result=$(openim::util::kill_exist_binary "$full_path" | tail -n1) - echo "result $result" - if [ "$result" -eq 0 ]; then - echo "$full_path no exist" - else - echo "$full_path running. waiting stop" - fi - done -} - - -check_all_stop() { - for binary in "${!binaries[@]}"; do - expected_count=${binaries[$binary]} - full_path=$(get_bin_full_path "$binary") - - result=$(openim::util::check_process_names_exist "$full_path") - if [ "$result" -ne 0 ]; then - echo "Process for $binary is still running. Aborting..." - exit 1 - fi - done - echo "All processes have been stopped." -} kill_exist_binaries -check_all_stop +result=$(check_binaries_stop) +ret_val=$? + +if [ $ret_val -eq 0 ]; then + echo "All binaries are stopped." +else + echo "$result" + echo "abort..." + exit 1 +fi + # Call the main function start_binaries +check_binaries_running + +print_listened_ports_by_binaries + diff --git a/scripts-new/stop.sh b/scripts-new/stop.sh index 5dca030c0..80ad52f5d 100644 --- a/scripts-new/stop.sh +++ b/scripts-new/stop.sh @@ -10,10 +10,5 @@ source "${OPENIM_ROOT}/lib/path.sh" -for binary in "${!binaries[@]}"; do - expected_count=${binaries[$binary]} - full_path=$(get_bin_full_path "$binary") - kill_binary "$full_path" -done