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

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

更正錯字

File size: 12.7 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
[176]17Tomcat_HOME=/opt/nutchez/tomcat
[171]18NutchEZ_HOME=/home/nutchuser/nutchez
19
[172]20# [Functions Declaration] #
21## [Prepare Check]  ##
[162]22function prepare_check(){ 
[172]23# 若無 nutchez_nodes 則跳出
24if [ ! -e "${NutchEZ_HOME}/system/nutch_nodes" ]; then
[165]25    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[nutch_nodes Files]" \
[172]26    --msgbox "Fail: Don't find $NutchEZ_HOME/system/nutch_nodes !!!" 10 40
[162]27    exit
28fi
29
[172]30# 判斷 nutch_nodes 和 nutch_nodes.back
31# 第一次執行則要求 user 更新 /etc/hosts
32if [ ! -e "${NutchEZ_HOME}/system/nutch_nodes.bak" ]; then
33    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[/etc/host Update]" \
34    --yesno "First execut nutchez management interface.\nPlz update /etc/hosts !!!" 10 55
[162]35
[172]36    echo -e "Plz input root password to update /etc/hosts !!!"
37    ./duplicate_del "${NutchEZ_HOME}/system/nutch_nodes"
38    su root -c "./duplicate_del /etc/hosts && ./add_hosts ${NutchEZ_HOME}/system/nutch_nodes /etc/hosts"
39    # 若密碼輸入失敗則跳出
40    if [ $? == "1" ]; then
41        echo "Root password is error ! Plz check root password !!!"
42        exit
43    fi 
44# 若 nutch_nodes 被更新過,則要求更新 /etc/hosts
45elif [ ${NutchEZ_HOME}/system/nutch_nodes -nt ${NutchEZ_HOME}/system/nutch_nodes.bak ]; then
46    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[/etc/host Update]" \
47    --yesno "nutch_nodes already be modified.\nPlz update /etc/hosts !!!" 10 55
[165]48
[172]49    echo -e "Plz input root password to update /etc/hosts !!!"
50    ./duplicate_del "${NutchEZ_HOME}/system/nutch_nodes"
51    su root -c "./duplicate_del /etc/hosts && ./add_hosts ${NutchEZ_HOME}/system/nutch_nodes /etc/hosts"
52    # 若密碼輸入失敗則跳出                   
53    if [ $? == "1" ]; then                   
54        echo "Root password is error ! Plz check root password !!!"
55        exit                                 
56    fi
57fi
[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]" \
[183]66        --menu "Plz choose: " 15 60 7 \
[174]67        "cluster_status" "Check cluster status" \
[183]68        "server_setup" "Setup namenode & jobtracker" \
69        "cluster_setup" "Setup datanode & tasktracker" \
[162]70        "tomcat_switch" "Start/Stop/Restart Tomcat" \
71        "tomcat_port" "Change Tomcat port" \
72        "lang_switch" "Change language" \
73        "exit" "Exit" 2>$main_choice
74}
75
[174]76## [Cluster Status (datanode & tasktracker)] ##
77function cluster_status(){
78IP_list=$(cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#'  | awk '{print $1}')
79clusterStatus="/tmp/clusterStatus"
80rm $clusterStatus 2> /dev/null
81#printf '%16s\t %11s\t %10s\t %25s\n' "[IP] [Hostanme] [Network] [Dtatnode & Tasktracker]" >>$clusterStatus
[176]82echo -e "[IP] \t\t [Hostname] \t [Network] \t [Dtatnode & Tasktracker]" >>$clusterStatus
[174]83echo -e "------------------------------------------------------------------------" >>$clusterStatus
84echo -e "\nStart to check cluster..."
85for ip in $IP_list
86do
87    # Check Network status
88    ip_status="online"
89    ping -c1 -w1 $ip 2>&1 > /dev/null || ip_status="offline"
90    # Check Hadoop/Nutch service through ssh
91    Task_Data_status="stop"
92    if [ $ip_status == "online" ]; then
93    Task_Data=$(ssh -o StrictHostKeyChecking=no $ip "jps |grep TaskTracker ; jps | grep  DataNode")
94    fi
95
96#   if [ $? == "255" ]; then
97#   echo -e "$ip Network is down"
98#   elif [ $? == "1" ]; then
99#   echo -e "Can't ssh to $ip"
100#   fi
101
[175]102    [ -z "$Task_Data" ] || Task_Data_status="running"
[174]103    host_name=$(cat $NutchEZ_HOME/system/nutch_nodes | grep $ip | awk '{print $2}')
104    echo  -e "$ip  $host_name \t\t $ip_status \t $Task_Data_status" >>$clusterStatus
105#    printf '%16s\t %11s\t %10s\t %25s\n' "$ip $host_name $ip_status $Task_Data_status" >>$clusterStatus
106done
107
108read -p "Plz input anykey to continue..."
109$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" \
110     --title "[Cluster Status]" --textbox $clusterStatus 20 90
111}
112
[183]113
114## [Cluster Setup (namenode & jobtracker)] ##
115function server_setup(){
116serverSetup=/tmp/serverSetup
117pid_name=$(jps | grep NameNode)
118pid_job=$(jps | grep JobTracker)
119
120if [ -z "$pid_name" -a -z "$pid_job" ]; then                                                                                               
121    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Server Status]" \
122    --msgbox "Namenode & Jobtracker are not running" 7 50
123elif [ -z "$pid_name" -a -n "$pid_job" ]; then
124    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Server Status]" \
125    --msgbox "Jobtracker is running, Namenode is not running" 7 50
126elif [ -n "$pid_name" -a -z "$pid_job" ]; then
127    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Server Status]" \
128    --msgbox "Namenode is running, Jobtracker is not running" 7 50
129else
130    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Server Status]" \
131    --msgbox "Namenode & Jobtracker are running" 7 50
132fi
133
134$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Namenode & Jobtracker Setup]" \
135    --menu "Plz choose: " 15 65 4 \
136    "start" "Start namenode & jobtracker" \
137    "stop" "Stop namenode & jobtracker" \
138    "restart" "restart namenode & jobtracker" \
139    "exit" "Exit" 2>$serverSetup
140
141if [ "$(cat $serverSetup)" == "start" ]; then
142    $NutchEZ_Install_PATH/nutch/bin/start-dfs.sh
143    $NutchEZ_Install_PATH/nutch/bin/start-mapred.sh
144elif [ "$(cat $serverSetup)" == "stop" ]; then
145    $NutchEZ_Install_PATH/nutch/bin/stop-dfs.sh
146    $NutchEZ_Install_PATH/nutch/bin/stop-mapred.sh
147elif [ "$(cat $serverSetup)" == "restart" ]; then
148    $NutchEZ_Install_PATH/nutch/bin/stop-dfs.sh
149    $NutchEZ_Install_PATH/nutch/bin/stop-mapred.sh
150    $NutchEZ_Install_PATH/nutch/bin/start-dfs.sh
151    $NutchEZ_Install_PATH/nutch/bin/start-mapred.sh
152else
153    exit
154fi
155
156
157}
158
159
[172]160## [Cluster Setup (datanode & tasktracker)] ##
[162]161function cluster_setup(){
[172]162# 從 nutch_nodes 讀出 ip 和 hostname
163#IP_list=$(cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#' | awk '{print $1}')
164#HOST_list=$(cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#' | awk '{print $2}')
165LIST_status="off"
166allpart="/tmp/allpart"
167runNodes="/tmp/runNodes"
168clusterSetup="/tmp/clusterSetup"
[162]169
[172]170$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" \
171    --title "[Management Options]" \
[177]172    --menu "Plz choose: " 15 55 3 \
[172]173    "All" "All nodes" \
[177]174    "Part" "Choose part nodess" \
175    "Exit" "Exit" 2>$allpart
[162]176
[172]177# 判斷是否選 all 和 part,若是 all 直接到服務選單,若是 part 則先到機器選單
[177]178if [ "$(cat $allpart)" == "All" ]; then
[172]179     cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#'  | awk '{print $1}' >$runNodes
[177]180elif [ "$(cat $allpart)" == "Part" ]; then
[172]181    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC  = " --title "[Datanode & Tasktracker Nodes Choose]" \
[177]182    --checklist "datanode & tasktracker choose: " 15 55 7 $(cat $NutchEZ_HOME/system/nutch_nodes | \
[172]183    grep -v '^$' | grep -v '#'  | awk '{print $1 "\t" $2 "\t" "$LIST_status" }') 2>$runNodes
[177]184else
185    exit
[172]186fi
187
[177]188if [ -z "$(cat $runNodes)" ]; then
[180]189    exit
190else
191    $(cat $runNodes) | sed -i 's/"//g' $runNodes 
[177]192fi
193
[165]194$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Datanode & Tasktracker Setup]" \
[176]195    --menu "Plz choose: " 15 65 4 \
[172]196    "start" "Start datanodes & tasktrackers" \
197    "stop" "Stop datanodes & tasktrackers" \
198    "restart" "restart datanodes & tasktrackers" \
[162]199    "exit" "Exit" 2>$clusterSetup
200
201if [ "$(cat $clusterSetup)" == "start" ]; then
[176]202    echo -e "\n[Start datanode & tasktracker]"
[172]203    for node in $(cat $runNodes)
[162]204    do
[176]205        echo -e "start $node datanode & tasktracker !"
206        ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start datanode \
207        ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start tasktracker"
[172]208        [ $? == "0" ] || echo "Can't ssh to $node !!!"
[162]209    done
210elif [ "$(cat $clusterSetup)" == "stop" ]; then
[176]211    echo -e "\n[Stop datanode & tasktracker]"
[172]212    for node in $(cat $runNodes)
[162]213    do
[176]214        echo -e "stop $node datanode & tasktracker !"
215        ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop datanode \
216        ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop tasktracker"
[172]217        [ $? == "0" ] || echo "Can't ssh to $node !!!"
[162]218    done
[177]219elif [ "$(cat $clusterSetup)" == "restart"  ]; then
[176]220    echo -e "\n[Restart datanode & tasktracker]"
[172]221    for node in $(cat $runNodes)
222    do 
[176]223        echo -e "restart $node datanode & tasktracker !"
224        ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop datanode \
[177]225        ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop tasktracker \
226        ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start datanode \
[176]227        ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start tasktracker"
[172]228        [ $? == "0" ] || echo "Can't ssh to $node !!!"
229    done
[177]230else
231    exit
[162]232fi
233}
234
[172]235## [Tomcat Severice start/stop/restart] ##
[162]236function tomcat_switch(){
237pid_tc=$(ps axw -eo pid,command | grep "catalina" | grep "java" | grep "start" | awk '{print $1}')
238#echo $pid_tc
239#read
240if [ -n "$pid_tc" ]; then
[165]241    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \
242        --msgbox "Tomcat is runing in this system !!!" 7 50
[162]243else
[165]244    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \
245        --msgbox "Tomcat is not running in this system !!!" 7 50
[162]246fi
247tomcatSwitch="/tmp/tomcatSwitch"
[165]248$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Service Options]" \
[162]249    --menu "Plz choose: " 15 55 4 \
250        "start" "Start tomcat" \
251        "stop" "Stop tomcat" \
252        "restart" "Restart tomcat" \
253        "exit" "Exit" 2>$tomcatSwitch
254
[177]255if [ "$(cat $tomcatSwitch)" == "exit" ]; then
256    exit 0
257fi
258
259# jude $Tomcat_HOME/bin/startup.sh
260if [ ! -e $Tomcat_HOME/bin/startup.sh ]; then
261    echo -e "\nDon't fine $Tomcat_HOME/bin/startup.sh"
262    exit
263fi
264
[184]265if [ ! -e $Tomcat_HOME/bin/shutdown.sh ]; then
[179]266    echo -e "\nDon't fine $Tomcat_HOME/bin/shutdown.sh"
[177]267    exit
268fi
269
[162]270if [ "$(cat $tomcatSwitch)" == "start" ]; then
[176]271    echo "$Tomcat_HOME/bin/startup.sh"
272    $Tomcat_HOME/bin/startup.sh
[162]273elif [ "$(cat $tomcatSwitch)" == "stop" ]; then
[176]274    echo "$Tomcat_HOME/bin/shutdown.sh"
275    $Tomcat_HOME/bin/shutdown.sh
[162]276elif [ "$(cat $tomcatSwitch)" == "restart" ]; then
[176]277    echo "$Tomcat_HOME/bin/restart.sh"
278    $Tomcat_HOME/bin/shutdown.sh
279    $Tomcat_HOME/bin/startup.sh
[162]280else
281    exit 0
282fi
283}
284
[172]285## [Tomcat Port Change] ##
[162]286function tomcat_port(){
287
[176]288if [ ! -e $Tomcat_HOME/conf/server.xml ]; then
[165]289    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Servel.xml]" \
[176]290        --msgbox "Fial: Don't find $Tomcat_HOME/conf/server.xml !!!" 10 50
[162]291    exit
292fi
293tomcatPort="/tmp/tomcatPort"
[165]294$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC  = " --title "[Tomcat Port Change]" \
[162]295    --inputbox "Plz input port number for tomcat (default is 8080)" 10 55 2>$tomcatPort
296
[177]297if [ -z "$(cat $tomcatPort)" ]; then
[162]298    exit
299else
[176]300    modify_line_nu=$(cat -n $Tomcat_HOME/conf/server.xml | grep -v SSL | grep 'HTTP/1.1' | grep '<Connector' | awk '{print $1}')
[182]301    sed -i "${modify_line_nu}c <Connector port=\"$(cat $tomcatPort)\" protocol=\"HTTP/1.1\"" $Tomcat_HOME/conf/server.xml
[176]302    $Tomcat_HOME/bin/shutdown.sh
303    $Tomcat_HOME/bin/startup.sh
[162]304fi
[176]305
306
[162]307}
308
309
[172]310## [Language Change] ##
[162]311function lang_switch(){
312echo -e "lang_switch"
313langSwitch="/tmp/langSwitch"
[165]314$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC  =" --title "[Language Swaitch]" \
[162]315    --menu "Plz choose: " 15 55 3 \
316    "English" "English" \
[177]317    "Chinese" "Chinese" \
318    "Exit" "Exit" 2>$langSwitch
[162]319#
[177]320if [ "$(cat $langSwitch)" == "Exit" ]; then
321    exit
322else
323    echo "source $(cat $langSwitch)"
324fi
[162]325}
326
327
[172]328# [Main Code] #
[162]329if [ $USER != "nutchuser" ]; then
330    echo -e "\nYour identify is not nutchuser, plz change to \"nutchuser\" !!!"
331    exit
332fi
333
334prepare_check
335main_menu
336case $(cat $main_choice) in
[174]337    "cluster_status")
338        cluster_status;;
[183]339    "server_setup")   
340        server_setup;;
[162]341    "cluster_setup")
342        cluster_setup;;
343    "tomcat_switch")
344        tomcat_switch;;
345    "tomcat_port")
346        tomcat_port;;
347    "lang_switch")
348        lang_switch;;
349esac
Note: See TracBrowser for help on using the repository browser.