source: nutchez-0.2/src/test/client_remove.sh @ 204

Last change on this file since 204 was 204, checked in by shunfa, 14 years ago

修改client移除程式

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1#!/bin/bash
2# Program:
3#   remove shell script for client uninstall
4# Author:
5#   Waue, Shunfa, Rock {waue, shunfa, rock}@nchc.org.tw
6# Version:
7#    1.0
8# History:
9#   
10
11
12source ./lang_zh_TW_client_remove
13# 需要 master_install 設定的參數區
14# Master IP here
15Master_IP_Address=input.your.master.ip_address
16# Master Hostname here
17Master_Hostname=input_your_master_hostname
18
19##########  echo function  ##########
20function debug_info () {
21  if [ $? -eq 0 ]; then
22    echo -e "\033[1;35;40m info - $1 \033[0m"
23  fi
24}
25
26
27function show_info () {
28  if [ $? -eq 0 ]; then
29    echo -e "\033[1;32;40m $1 \033[0m"
30  fi
31}
32##########end echo function ##########
33
34# check root
35function check_root(){
36  debug_info "check_root"
37  if [ $USER != "root" ]; then
38    show_info "$check_root_1" # "請切換成 root 身份執行移除程式!!!"
39    exit
40  fi
41  show_info "$check_root_2" # "已確認為root身份, 將繼續執行此移除程式!"
42}
43
44# shutdown service
45function shutdown_service () {
46  show_info "$shutdown_service_echo_1" # "關閉本機服務..."
47  su nutchuser -c "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop datanode"
48  su nutchuser -c "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop tasktracker"
49  show_info "$shutdown_service_echo_2" # "本機服務已關閉"
50}
51
52# 移除檔案及資料夾
53function remove_folders () {
54  show_info "$remove_folders_echo_1" # "正在刪除安裝時所建立的檔案及資料夾..."
55  rm -rf /opt/nutchez/*
56  rm -rf /var/nutchez/*
57  show_info "$remove_folders_echo_2" # "安裝時所建立的檔案及資料夾已刪除"
58}
59
60
61# 還原/etc/hosts
62function edit_hosts () {
63  show_info "$edit_hosts_echo_1" # "修改/etc/hosts..."
64  Line_NO=`cat /etc/hosts | grep -n $Master_IP_Address | sed 's/:.*//g'`
65  sed -i ''$Line_NO'd' /etc/hosts
66  show_info "$edit_hosts_echo_2" # "完成修改/etc/hosts"
67}
68
69
70# 移除使用者
71function user_delete () {
72  show_info "$user_delete_echo_1" # "正在刪除nutchuser使用者..."
73  userdel -r nutcheruser
74  show_info "$user_delete_echo_2" # "使用者nutchuser已刪除"
75}
76
77# Main function
78function main () {
79  show_info "$main_echo_1" #"警告 - 此一程式為移除此用戶端的nutch node, 若您為誤執行此一程式, 請按Ctrl+c離開此程序!"
80  show_info "$main_echo_2" #"本執行程序將會移除安裝nutchEZ時所新增的檔案及nutchuser使用者帳號"
81# 詢問是否繼續
82  read -p "$main_echo_3" confirm # "請問是否確定移除此一節點:1.確定 2.取消"
83# 確認移除
84  if [ $confirm -eq 1 ]; then
85    check_root
86    shutdown_service
87    remove_folders
88    edit_hosts
89    user_delete
90    show_info "$main_echo_4" # "移除程序已完成!"
91  elif [ $confirm -eq 2 ]; then
92    show_info "$main_echo_5" # "您已取消移除程序!"
93    show_info "$main_echo_6" # "若要移除請再重新執行!"
94  fi
95}
96
97main
Note: See TracBrowser for help on using the repository browser.