source: nutchez-0.2/src/test/nutchez @ 175

Last change on this file since 175 was 175, checked in by rock, 14 years ago

修改小bug

File size: 10.4 KB
RevLine 
[162]1#!/bin/bash
2# Program:
3#   NutchEz management interface
4# Author:
5#   Waue, Shunfa, Rock {waue, shunfa, rock}@nchc.org.tw
6# Version:
7#    1.0
8# History:
9#   2010/06/07  Rock    First release (1.0)
10
[172]11# [Variables Declaration] #
[162]12DIALOG=dialog
13main_choice=
14
[172]15# [PATH Declaration] #
[171]16NutchEZ_Install_PATH=/opt/nutchez
17NutchEZ_HOME=/home/nutchuser/nutchez
18
[172]19# [Functions Declaration] #
20## [Prepare Check]  ##
[162]21function prepare_check(){ 
[172]22# 若無 nutchez_nodes 則跳出
23if [ ! -e "${NutchEZ_HOME}/system/nutch_nodes" ]; then
[165]24    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[nutch_nodes Files]" \
[172]25    --msgbox "Fail: Don't find $NutchEZ_HOME/system/nutch_nodes !!!" 10 40
[162]26    exit
27fi
28
[172]29# 判斷 nutch_nodes 和 nutch_nodes.back
30# 第一次執行則要求 user 更新 /etc/hosts
31if [ ! -e "${NutchEZ_HOME}/system/nutch_nodes.bak" ]; then
32    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[/etc/host Update]" \
33    --yesno "First execut nutchez management interface.\nPlz update /etc/hosts !!!" 10 55
[162]34
[172]35    echo -e "Plz input root password to update /etc/hosts !!!"
36    ./duplicate_del "${NutchEZ_HOME}/system/nutch_nodes"
37    su root -c "./duplicate_del /etc/hosts && ./add_hosts ${NutchEZ_HOME}/system/nutch_nodes /etc/hosts"
38    # 若密碼輸入失敗則跳出
39    if [ $? == "1" ]; then
40        echo "Root password is error ! Plz check root password !!!"
41        exit
42    fi 
43# 若 nutch_nodes 被更新過,則要求更新 /etc/hosts
44elif [ ${NutchEZ_HOME}/system/nutch_nodes -nt ${NutchEZ_HOME}/system/nutch_nodes.bak ]; then
45    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[/etc/host Update]" \
46    --yesno "nutch_nodes already be modified.\nPlz update /etc/hosts !!!" 10 55
[165]47
[172]48    echo -e "Plz input root password to update /etc/hosts !!!"
49    ./duplicate_del "${NutchEZ_HOME}/system/nutch_nodes"
50    su root -c "./duplicate_del /etc/hosts && ./add_hosts ${NutchEZ_HOME}/system/nutch_nodes /etc/hosts"
51    # 若密碼輸入失敗則跳出                   
52    if [ $? == "1" ]; then                   
53        echo "Root password is error ! Plz check root password !!!"
54        exit                                 
55    fi
56fi
57
[162]58}
59
[172]60## [Main Menu] ##
[162]61function main_menu(){
62main_choice="/tmp/main_choice"
63
64$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" \
[165]65    --title "[Management Options]" \
[174]66        --menu "Plz choose: " 15 55 6 \
67        "cluster_status" "Check cluster status" \
[165]68        "cluster_setup" "Setup your datanode & tasktracker" \
[162]69        "tomcat_switch" "Start/Stop/Restart Tomcat" \
70        "tomcat_port" "Change Tomcat port" \
71        "lang_switch" "Change language" \
72        "exit" "Exit" 2>$main_choice
73}
74
[174]75## [Cluster Status (datanode & tasktracker)] ##
76function cluster_status(){
77IP_list=$(cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#'  | awk '{print $1}')
78clusterStatus="/tmp/clusterStatus"
79rm $clusterStatus 2> /dev/null
80#printf '%16s\t %11s\t %10s\t %25s\n' "[IP] [Hostanme] [Network] [Dtatnode & Tasktracker]" >>$clusterStatus
81echo -e "[IP] \t\t [Hostanme] \t [Network] \t [Dtatnode & Tasktracker]" >>$clusterStatus
82echo -e "------------------------------------------------------------------------" >>$clusterStatus
83echo -e "\nStart to check cluster..."
84for ip in $IP_list
85do
86    # Check Network status
87    ip_status="online"
88    ping -c1 -w1 $ip 2>&1 > /dev/null || ip_status="offline"
89    # Check Hadoop/Nutch service through ssh
90    Task_Data_status="stop"
91    if [ $ip_status == "online" ]; then
92    Task_Data=$(ssh -o StrictHostKeyChecking=no $ip "jps |grep TaskTracker ; jps | grep  DataNode")
93    fi
94
95#   if [ $? == "255" ]; then
96#   echo -e "$ip Network is down"
97#   elif [ $? == "1" ]; then
98#   echo -e "Can't ssh to $ip"
99#   fi
100
[175]101    [ -z "$Task_Data" ] || Task_Data_status="running"
[174]102    host_name=$(cat $NutchEZ_HOME/system/nutch_nodes | grep $ip | awk '{print $2}')
103    echo  -e "$ip  $host_name \t\t $ip_status \t $Task_Data_status" >>$clusterStatus
104#    printf '%16s\t %11s\t %10s\t %25s\n' "$ip $host_name $ip_status $Task_Data_status" >>$clusterStatus
105done
106
107read -p "Plz input anykey to continue..."
108$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" \
109     --title "[Cluster Status]" --textbox $clusterStatus 20 90
110}
111
[172]112## [Cluster Setup (datanode & tasktracker)] ##
[162]113function cluster_setup(){
[172]114# 從 nutch_nodes 讀出 ip 和 hostname
115#IP_list=$(cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#' | awk '{print $1}')
116#HOST_list=$(cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#' | awk '{print $2}')
117LIST_status="off"
118allpart="/tmp/allpart"
119runNodes="/tmp/runNodes"
120clusterSetup="/tmp/clusterSetup"
[162]121
[172]122$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" \
123    --title "[Management Options]" \
124    --menu "Plz choose: " 15 55 2 \
125    "All" "All nodes" \
126    "Part" "choose part nodess" 2>$allpart
[162]127
[172]128# 判斷是否選 all 和 part,若是 all 直接到服務選單,若是 part 則先到機器選單
129if [ $(cat $allpart) == "All" ]; then
130     cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#'  | awk '{print $1}' >$runNodes
131else
132    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC  = " --title "[Datanode & Tasktracker Nodes Choose]" \
133    --checklist "datanode & tasktracker choose: " 15 55 7 $(cat  $NutchEZ_HOME/system/nutch_nodes | \
134    grep -v '^$' | grep -v '#'  | awk '{print $1 "\t" $2 "\t" "$LIST_status" }') 2>$runNodes
135fi
136
[165]137$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Datanode & Tasktracker Setup]" \
[162]138    --menu "Plz choose: " 10 65 3 \
[172]139    "start" "Start datanodes & tasktrackers" \
140    "stop" "Stop datanodes & tasktrackers" \
141    "restart" "restart datanodes & tasktrackers" \
[162]142    "exit" "Exit" 2>$clusterSetup
143
144if [ "$(cat $clusterSetup)" == "start" ]; then
[172]145    for node in $(cat $runNodes)
[162]146    do
[172]147        echo -e "start !"
[165]148        echo -e "ssh -o StrictHostKeyChecking=no $node /opt/nutchez/nutch/bin/hadoop-daemon.sh start datanode"
[170]149        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh start datanode"
[165]150        echo -e "ssh -o StrictHostKeyChecking=no $node /opt/nutchez/nutch/bin/hadoop-daemon.sh start tasktracker"
[170]151        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh start tasktracker"
[172]152        [ $? == "0" ] || echo "Can't ssh to $node !!!"
[162]153    done
154elif [ "$(cat $clusterSetup)" == "stop" ]; then
[172]155    for node in $(cat $runNodes)
[162]156    do
[172]157        echo -e "stop !"
[165]158        echo -e "ssh -o StrictHostKeyChecking=no $node /opt/nutchez/nutch/bin/hadoop-daemon.sh stop datanode"
[170]159        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop datanode"
[165]160        echo -e "ssh -o StrictHostKeyChecking=no $node /opt/nutchez/nutch/bin/hadoop-daemon.sh stop tasktracker"
[170]161        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop tasktracker"
[172]162        [ $? == "0" ] || echo "Can't ssh to $node !!!"
[162]163    done
164else
[172]165    for node in $(cat $runNodes)
166    do 
167        echo -e "restart !"
168        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop datanode"
169        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop tasktracker"
170        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh start datanode"
171        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh start tasktracker"
172        [ $? == "0" ] || echo "Can't ssh to $node !!!"
173    done
174 
[162]175fi
176}
177
[172]178## [Tomcat Severice start/stop/restart] ##
[162]179function tomcat_switch(){
180pid_tc=$(ps axw -eo pid,command | grep "catalina" | grep "java" | grep "start" | awk '{print $1}')
181#echo $pid_tc
182#read
183if [ -n "$pid_tc" ]; then
[165]184    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \
185        --msgbox "Tomcat is runing in this system !!!" 7 50
[162]186else
[165]187    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \
188        --msgbox "Tomcat is not running in this system !!!" 7 50
[162]189fi
190tomcatSwitch="/tmp/tomcatSwitch"
[165]191$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Service Options]" \
[162]192    --menu "Plz choose: " 15 55 4 \
193        "start" "Start tomcat" \
194        "stop" "Stop tomcat" \
195        "restart" "Restart tomcat" \
196        "exit" "Exit" 2>$tomcatSwitch
197
198if [ "$(cat $tomcatSwitch)" == "start" ]; then
199    echo "/opt/nutchez/tomcat/bin/startup.sh"
200    /opt/nutchez/tomcat/bin/startup.sh
201elif [ "$(cat $tomcatSwitch)" == "stop" ]; then
202    echo "/opt/nutchez/tomcat/bin/shutdown.sh"
203    /opt/nutchez/tomcat/bin/shutdown.sh
204elif [ "$(cat $tomcatSwitch)" == "restart" ]; then
205    echo "/opt/nutchez/tomcat/bin/restart.sh"
206    /opt/nutchez/tomcat/bin/shutdown.sh
207    /opt/nutchez/tomcat/bin/startup.sh
208else
209    exit 0
210fi
211}
212
[172]213## [Tomcat Port Change] ##
[162]214function tomcat_port(){
215
216if [ ! -e /opt/nutchez/tomcat/conf/server.xml ]; then
[165]217    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Servel.xml]" \
[162]218        --msgbox "Fial: Don't find /opt/nutchez/tomcat/conf/server.xml !!!" 10 50
219    exit
220fi
221tomcatPort="/tmp/tomcatPort"
[165]222$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC  = " --title "[Tomcat Port Change]" \
[162]223    --inputbox "Plz input port number for tomcat (default is 8080)" 10 55 2>$tomcatPort
224
225if [ -z $(cat $tomcatPort) ]; then
226    exit
227else
228    modify_line_nu=$(cat -n /opt/nutchez/tomcat/conf/server.xml | grep -v SSL | grep 'HTTP/1.1' | grep '<Connector' | awk '{print $1}')
229    sed -i "${modify_line_nu}c <Connector port="$tomcatPort" protocol="HTTP/1.1"" /opt/nutchez/tomcat/conf/server.xml
230fi
231}
232
233
[172]234## [Language Change] ##
[162]235function lang_switch(){
236echo -e "lang_switch"
237langSwitch="/tmp/langSwitch"
[165]238$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC  =" --title "[Language Swaitch]" \
[162]239    --menu "Plz choose: " 15 55 3 \
240    "English" "English" \
241    "Chinese" "Chinese" 2>$langSwitch
242#
243echo "source $(cat $langSwitch)"
244}
245
246
[172]247# [Main Code] #
[162]248if [ $USER != "nutchuser" ]; then
249    echo -e "\nYour identify is not nutchuser, plz change to \"nutchuser\" !!!"
250    exit
251fi
252
253prepare_check
254main_menu
255case $(cat $main_choice) in
[174]256    "cluster_status")
257        cluster_status;;
[162]258    "cluster_setup")
259        cluster_setup;;
260    "tomcat_switch")
261        tomcat_switch;;
262    "tomcat_port")
263        tomcat_port;;
264    "lang_switch")
265        lang_switch;;
266esac
Note: See TracBrowser for help on using the repository browser.