403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /opt/webdir/bin/menu/01_hosts/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /opt/webdir/bin/menu/01_hosts/07_remove_pool.sh
#!/usr/bin/bash
#
PROGNAME=$(basename $0)
PROGPATH=$(dirname $0)

. $PROGPATH/functions.sh || exit 1
[[ -z $DEBUG ]] && DEBUG=0

# return 0 - we will delete pool
# return 1 - found mysql cluster
# return 2 - found web cluster
# return 3 - found mysql server on another server in the group
# return 255 - something else
test_delete_conditions() {
    [[ -z $POOL_SERVER_LIST  ]] && cache_pool_info
    DESCRIBE_MESSAGE=

    # found not connected servers
    if [[ -n "$POOL_UNU_SERVER_LIST" ]]; then
        server_list=$(echo "$POOL_UNU_SERVER_LIST" | \
            awk -F':' '{printf "%s, ", $1}' | sed -e 's/^, //;s/, $//;')
        DESCRIBE_MESSAGE="$(get_text "$HM0026" "$server_list")"
        DESCRIBE_MESSAGE="$DESCRIBE_MESSAGE
        $HM0067"
        return 255
    fi
    [[ $DEBUG -gt 0 ]] && echo "POOL_SERVER_LIST=$POOL_SERVER_LIST"

    local cnt_mysql=$(echo "$POOL_SERVER_LIST" | awk -F':' '{print $3}'| grep -c 'mysql')
    local cnt_web=$(echo "$POOL_SERVER_LIST" | awk -F':' '{print $3}'| grep -c 'web')

    local mgmt_is_master=$(echo "$POOL_SERVER_LIST" | grep mysql_master | \
        awk -F':' '{print $3}' | grep -cw "mgmt")
    local master_name=$(echo "$POOL_SERVER_LIST" | grep mysql_master | \
        awk -F':' '{print $1}' | sed -e 's/^\s\+//;s/\s\+$//')

    [[ $DEBUG -gt 0 ]] && echo "cnt_mysql=$cnt_mysql cnt_web=$cnt_web mgmt_is_master=$mgmt_is_master"

    if [[ $cnt_mysql -gt 1 ]]; then
        DESCRIBE_MESSAGE="$(get_text "$HM0068" "mysql")"
        return 1
    fi
    if [[ $cnt_web -gt 1 ]]; then
        DESCRIBE_MESSAGE="$(get_text "$HM0068" "web")"
        return 2
    fi

    if [[ $mgmt_is_master -eq 0 ]]; then
        DESCRIBE_MESSAGE="$(get_text "$HM0069" "$master_name")"
        return 3
    fi
    return 0
}

warn_and_remove() {
    print_color_text "$HM0070" red
    echo "$HM0071"
    echo
    # test conditions
    test_delete_conditions
    test_delete_conditions_rtn=$?
    if [[ $test_delete_conditions_rtn -gt 0 ]]; then
        print_message "$HM0200" "$DESCRIBE_MESSAGE" "" any_key
        return 1
    fi

    # deletion process
    print_message "$HM0072" "" "" confirm 'n'
    [[ $DEBUG -gt 0 ]] && echo $confirm
    [[ $(echo "$confirm" | grep -iwc 'n') -gt 0 ]] && return 1
    remove_pool
    if [[ $? -gt 0 ]]; then
        print_message "$HM0200" "$DELETE_MSG" "" any_key
        return 1
    else
        print_message "$HM0201" "$HM0073" "" any_key
        exit
    fi
}

menu_remove_pool() {
    local host_logo="$HM0074"
    local menu_00="$HM0042"
    local menu_01="1. $HM0074"

    HOST_MENU_SELECT=
    until [[ -n "$HOST_MENU_SELECT" ]]; do
        [[ $DEBUG -eq 0 ]] && clear
        echo -e "\t\t" $logo
        echo -e "\t\t" $host_logo
        echo

        print_pool_info

        menu_list="$menu_01\n\t\t $menu_00"
        print_menu

        print_message "$HM0204" '' '' HOST_MENU_SELECT
        # process selection
        case "$HOST_MENU_SELECT" in
            "0") exit ;;
            *) warn_and_remove ;;
        esac
        HOST_MENU_SELECT=
    done
}

menu_remove_pool

Youez - 2016 - github.com/yon3zu
LinuXploit