source: nutchez-0.2/src/shell/master_remove @ 234

Last change on this file since 234 was 233, checked in by shunfa, 15 years ago

關閉maste移除時, 檢查叢集狀態功能

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