[202] | 1 | #!/bin/bash |
---|
| 2 | # Program: |
---|
| 3 | # remove shell script for master uninstall |
---|
| 4 | # Author: |
---|
| 5 | # Waue, Shunfa, Rock {waue, shunfa, rock}@nchc.org.tw |
---|
| 6 | # Version: |
---|
| 7 | # 1.0 |
---|
| 8 | # History: |
---|
| 9 | # |
---|
| 10 | |
---|
[244] | 11 | #source /home/nutchuser/nutchez/system/lang_link |
---|
[202] | 12 | |
---|
| 13 | ########## echo function ########## |
---|
| 14 | function debug_info () { |
---|
| 15 | if [ $? -eq 0 ]; then |
---|
| 16 | echo -e "\033[1;35;40m info - $1 \033[0m" |
---|
| 17 | fi |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | function show_info () { |
---|
| 22 | if [ $? -eq 0 ]; then |
---|
| 23 | echo -e "\033[1;32;40m $1 \033[0m" |
---|
| 24 | fi |
---|
| 25 | } |
---|
| 26 | ##########end echo function ########## |
---|
| 27 | |
---|
| 28 | nutch_PATH=/home/nutchuser/nutchez/system |
---|
| 29 | |
---|
[244] | 30 | function load_default_lang(){ |
---|
[202] | 31 | |
---|
[244] | 32 | lang=$(locale | grep 'LANG=' | cut -d "=" -f2) |
---|
| 33 | |
---|
| 34 | # Default: source english |
---|
| 35 | . $Work_Path/lang/lang_en_US |
---|
| 36 | # if locale is zh then source chinese |
---|
| 37 | |
---|
| 38 | echo $lang | grep 'zh' >> /dev/null && source $Work_Path/lang/lang_zh_TW |
---|
| 39 | } |
---|
| 40 | |
---|
[202] | 41 | # check root |
---|
| 42 | function check_root(){ |
---|
| 43 | debug_info "check_root" |
---|
| 44 | if [ $USER != "root" ]; then |
---|
[213] | 45 | show_info "$MR_check_root_1" # "請切換成 root 身份執行移除程式!!!" |
---|
[202] | 46 | exit |
---|
| 47 | fi |
---|
[213] | 48 | show_info "$MR_check_root_2" # "已確認為root身份, 將繼續執行此移除程式!" |
---|
[202] | 49 | } |
---|
| 50 | |
---|
| 51 | # shutdown service |
---|
| 52 | function shutdown_service () { |
---|
[213] | 53 | show_info "$MR_shutdown_service_echo_1" # "停止其他尚未關閉的slaves服務..." |
---|
[202] | 54 | slaves_list=`cat $nutch_PATH'/nutch_nodes' | cut -d' ' -f1` |
---|
[226] | 55 | |
---|
[233] | 56 | # for nutch_node in $slaves_list |
---|
| 57 | # do |
---|
| 58 | # show_info "驗證叢集狀態" |
---|
| 59 | ## TaskTrackerStatus=`ssh -o StrictHostKeyChecking=no $nutch_node "jps |grep TaskTracker |sed 's/[0-9]* //g'"` |
---|
| 60 | ## DataNodeStatus=`ssh -o StrictHostKeyChecking=no $nutch_node "jps |grep DataNode |sed 's/[0-9]* //g'"` |
---|
[222] | 61 | |
---|
[233] | 62 | # if [ $(ssh -o StrictHostKeyChecking=no nutchuser@$nutch_node "jps |grep TaskTracker |sed 's/[0-9]* //g'") == "TaskTracker" ]; then |
---|
| 63 | # show_info "TaskTracker@$nutch_node is running, we will shutdown it!" |
---|
| 64 | # su nutchuser -c "ssh nutchuser@$nutch_node /opt/nutchez/nutch/bin/hadoop-daemon.sh stop tasktracker" |
---|
| 65 | # fi |
---|
[222] | 66 | |
---|
[233] | 67 | # if [ $(ssh -o StrictHostKeyChecking=no nutchuser@$nutch_node "jps |grep DataNode |sed 's/[0-9]* //g'") == "DataNode" ]; then |
---|
| 68 | # show_info "DataNode@$nutch_node is running, we will shutdown it!" |
---|
| 69 | # show_info "Shutdown $nutch_node." |
---|
| 70 | # su nutchuser -c "ssh nutchuser@$nutch_node /opt/nutchez/nutch/bin/hadoop-daemon.sh stop datanode" |
---|
| 71 | # fi |
---|
| 72 | # done |
---|
[213] | 73 | show_info "$MR_shutdown_service_echo_2" # "關閉本機服務..." |
---|
[202] | 74 | su nutchuser -c "/opt/nutchez/nutch/bin/stop-all.sh" |
---|
[206] | 75 | su nutchuser -c "/opt/nutchez/tomcat/bin/shutdown.sh" |
---|
[213] | 76 | show_info "$MR_shutdown_service_echo_3" # "本機服務已關閉" |
---|
[202] | 77 | } |
---|
| 78 | |
---|
| 79 | # 移除檔案及資料夾 |
---|
| 80 | function remove_folders () { |
---|
[224] | 81 | rm /usr/local/bin/nutchez |
---|
[213] | 82 | show_info "$MR_remove_folders_echo_1" # "正在刪除安裝時所建立的檔案及資料夾..." |
---|
[206] | 83 | rm -rf /opt/nutchez |
---|
| 84 | rm -rf /var/nutchez |
---|
[213] | 85 | show_info "$MR_remove_folders_echo_2" # "安裝時所建立的檔案及資料夾已刪除" |
---|
[202] | 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | # 還原/etc/hosts |
---|
| 90 | function edit_hosts () { |
---|
[213] | 91 | show_info "$MR_edit_hosts_echo_1" # "修改/etc/hosts..." |
---|
| 92 | # slaves_list=`cat $nutch_PATH'/nutch_nodes' | cut -d' ' -f1` |
---|
| 93 | # for nutch_node in $slaves_list |
---|
| 94 | # do |
---|
| 95 | # Line_NO=`cat /etc/hosts | grep -n $nutch_node | sed 's/:.*//g'` |
---|
| 96 | # if [[ $Line_NO -ge 1 ]]; then |
---|
| 97 | # sed -i ''$Line_NO'd' /etc/hosts |
---|
| 98 | # fi |
---|
| 99 | # done |
---|
| 100 | cat > /etc/hosts < /home/nutchuser/nutchez/system/hosts.bak |
---|
| 101 | show_info "$MR_edit_hosts_echo_2" # "完成修改/etc/hosts" |
---|
[202] | 102 | } |
---|
| 103 | |
---|
| 104 | # 移除使用者 |
---|
| 105 | function user_delete () { |
---|
[213] | 106 | show_info "$MR_user_delete_echo_1" # "正在刪除nutchuser使用者..." |
---|
[231] | 107 | userdel -rf nutchuser |
---|
[213] | 108 | show_info "$MR_user_delete_echo_2" # "使用者nutchuser已刪除" |
---|
[202] | 109 | } |
---|
| 110 | |
---|
| 111 | # Main function |
---|
| 112 | function main () { |
---|
[230] | 113 | check_root |
---|
[213] | 114 | show_info "$MR_main_echo_1" #"警告 - 此一程式為移除nutchEZ程式, 若您為誤執行此一程式, 請按Ctrl+c離開此程序!" |
---|
| 115 | show_info "$MR_main_echo_2" #"本執行程序將會移除安裝nutchEZ時所新增的檔案及nutchuser使用者帳號" |
---|
[202] | 116 | # 詢問是否繼續 |
---|
[213] | 117 | read -p "$MR_main_echo_3" confirm # "請問是否確定移除此一節點:1.確定 2.取消" |
---|
[202] | 118 | # 確認移除 |
---|
| 119 | if [ $confirm -eq 1 ]; then |
---|
| 120 | shutdown_service |
---|
| 121 | remove_folders |
---|
| 122 | edit_hosts |
---|
| 123 | user_delete |
---|
[213] | 124 | show_info "$MR_main_echo_4" # "移除程序已完成!" |
---|
[202] | 125 | elif [ $confirm -eq 2 ]; then |
---|
[213] | 126 | show_info "$MR_main_echo_5" # "您已取消移除程序!" |
---|
| 127 | show_info "$MR_main_echo_6" # "若要移除請再重新執行!" |
---|
[202] | 128 | fi |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | main |
---|
| 132 | |
---|