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

Last change on this file since 232 was 232, checked in by waue, 14 years ago

shell/client_install_func.sh 修改了 增加/var/nutchez/logs 否則鍊結會錯誤
其餘檔案則是統一命名法則,將使用者會執行的執行檔則不帶.sh副檔名,
而被引用的函式檔才帶入.sh副檔名,
因此,master_remove.sh => master_remove ; client_remove.sh => client_remove ;
install_func.sh 則修改相對應的檔名

  • Property svn:executable set to *
File size: 4.0 KB
Line 
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
11source /home/nutchuser/nutchez/system/lang_link
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
35    show_info "$MR_check_root_1" # "請切換成 root 身份執行移除程式!!!"
36    exit
37  fi
38  show_info "$MR_check_root_2" # "已確認為root身份, 將繼續執行此移除程式!"
39}
40
41# shutdown service
42function shutdown_service () {
43  show_info "$MR_shutdown_service_echo_1" # "停止其他尚未關閉的slaves服務..."
44  slaves_list=`cat $nutch_PATH'/nutch_nodes' | cut -d' ' -f1`
45 
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'"`
51
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
56
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
63  show_info "$MR_shutdown_service_echo_2" # "關閉本機服務..."
64  su nutchuser -c "/opt/nutchez/nutch/bin/stop-all.sh"
65  su nutchuser -c "/opt/nutchez/tomcat/bin/shutdown.sh"
66  show_info "$MR_shutdown_service_echo_3" # "本機服務已關閉"
67}
68
69# 移除檔案及資料夾
70function remove_folders () {
71  rm /usr/local/bin/nutchez
72  show_info "$MR_remove_folders_echo_1" # "正在刪除安裝時所建立的檔案及資料夾..."
73  rm -rf /opt/nutchez
74  rm -rf /var/nutchez
75  show_info "$MR_remove_folders_echo_2" # "安裝時所建立的檔案及資料夾已刪除"
76}
77
78
79# 還原/etc/hosts
80function edit_hosts () {
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"
92}
93
94# 移除使用者
95function user_delete () {
96  show_info "$MR_user_delete_echo_1" # "正在刪除nutchuser使用者..."
97  userdel -rf nutchuser
98  show_info "$MR_user_delete_echo_2" # "使用者nutchuser已刪除"
99}
100
101# Main function
102function main () {
103  check_root
104  show_info "$MR_main_echo_1" #"警告 - 此一程式為移除nutchEZ程式, 若您為誤執行此一程式, 請按Ctrl+c離開此程序!"
105  show_info "$MR_main_echo_2" #"本執行程序將會移除安裝nutchEZ時所新增的檔案及nutchuser使用者帳號"
106# 詢問是否繼續
107  read -p "$MR_main_echo_3" confirm # "請問是否確定移除此一節點:1.確定 2.取消"
108# 確認移除
109  if [ $confirm -eq 1 ]; then
110    shutdown_service
111    remove_folders
112    edit_hosts
113    user_delete
114    show_info "$MR_main_echo_4" # "移除程序已完成!"
115  elif [ $confirm -eq 2 ]; then
116    show_info "$MR_main_echo_5" # "您已取消移除程序!"
117    show_info "$MR_main_echo_6" # "若要移除請再重新執行!"
118  fi
119}
120
121main
122
Note: See TracBrowser for help on using the repository browser.