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

Last change on this file since 182 was 182, checked in by rock, 14 years ago
File size: 10.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]" \
[177]66        --menu "Plz choose: " 15 60 6 \
[174]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
[176]81echo -e "[IP] \t\t [Hostname] \t [Network] \t [Dtatnode & Tasktracker]" >>$clusterStatus
[174]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]" \
[177]124    --menu "Plz choose: " 15 55 3 \
[172]125    "All" "All nodes" \
[177]126    "Part" "Choose part nodess" \
127    "Exit" "Exit" 2>$allpart
[162]128
[172]129# 判斷是否選 all 和 part,若是 all 直接到服務選單,若是 part 則先到機器選單
[177]130if [ "$(cat $allpart)" == "All" ]; then
[172]131     cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#'  | awk '{print $1}' >$runNodes
[177]132elif [ "$(cat $allpart)" == "Part" ]; then
[172]133    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC  = " --title "[Datanode & Tasktracker Nodes Choose]" \
[177]134    --checklist "datanode & tasktracker choose: " 15 55 7 $(cat $NutchEZ_HOME/system/nutch_nodes | \
[172]135    grep -v '^$' | grep -v '#'  | awk '{print $1 "\t" $2 "\t" "$LIST_status" }') 2>$runNodes
[177]136else
137    exit
[172]138fi
139
[177]140if [ -z "$(cat $runNodes)" ]; then
[180]141    exit
142else
143    $(cat $runNodes) | sed -i 's/"//g' $runNodes 
[177]144fi
145
[165]146$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Datanode & Tasktracker Setup]" \
[176]147    --menu "Plz choose: " 15 65 4 \
[172]148    "start" "Start datanodes & tasktrackers" \
149    "stop" "Stop datanodes & tasktrackers" \
150    "restart" "restart datanodes & tasktrackers" \
[162]151    "exit" "Exit" 2>$clusterSetup
152
153if [ "$(cat $clusterSetup)" == "start" ]; then
[176]154    echo -e "\n[Start datanode & tasktracker]"
[172]155    for node in $(cat $runNodes)
[162]156    do
[176]157        echo -e "start $node datanode & tasktracker !"
158        ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start datanode \
159        ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start tasktracker"
[172]160        [ $? == "0" ] || echo "Can't ssh to $node !!!"
[162]161    done
162elif [ "$(cat $clusterSetup)" == "stop" ]; then
[176]163    echo -e "\n[Stop datanode & tasktracker]"
[172]164    for node in $(cat $runNodes)
[162]165    do
[176]166        echo -e "stop $node datanode & tasktracker !"
167        ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop datanode \
168        ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop tasktracker"
[172]169        [ $? == "0" ] || echo "Can't ssh to $node !!!"
[162]170    done
[177]171elif [ "$(cat $clusterSetup)" == "restart"  ]; then
[176]172    echo -e "\n[Restart datanode & tasktracker]"
[172]173    for node in $(cat $runNodes)
174    do 
[176]175        echo -e "restart $node datanode & tasktracker !"
176        ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop datanode \
[177]177        ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop tasktracker \
178        ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start datanode \
[176]179        ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start tasktracker"
[172]180        [ $? == "0" ] || echo "Can't ssh to $node !!!"
181    done
[177]182else
183    exit
[162]184fi
185}
186
[172]187## [Tomcat Severice start/stop/restart] ##
[162]188function tomcat_switch(){
189pid_tc=$(ps axw -eo pid,command | grep "catalina" | grep "java" | grep "start" | awk '{print $1}')
190#echo $pid_tc
191#read
192if [ -n "$pid_tc" ]; then
[165]193    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \
194        --msgbox "Tomcat is runing in this system !!!" 7 50
[162]195else
[165]196    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \
197        --msgbox "Tomcat is not running in this system !!!" 7 50
[162]198fi
199tomcatSwitch="/tmp/tomcatSwitch"
[165]200$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Service Options]" \
[162]201    --menu "Plz choose: " 15 55 4 \
202        "start" "Start tomcat" \
203        "stop" "Stop tomcat" \
204        "restart" "Restart tomcat" \
205        "exit" "Exit" 2>$tomcatSwitch
206
[177]207if [ "$(cat $tomcatSwitch)" == "exit" ]; then
208    exit 0
209fi
210
211# jude $Tomcat_HOME/bin/startup.sh
212if [ ! -e $Tomcat_HOME/bin/startup.sh ]; then
213    echo -e "\nDon't fine $Tomcat_HOME/bin/startup.sh"
214    exit
215fi
216
217if [ ! -e $Tomcat_HOME/bin/shudown.sh ]; then
[179]218    echo -e "\nDon't fine $Tomcat_HOME/bin/shutdown.sh"
[177]219    exit
220fi
221
[162]222if [ "$(cat $tomcatSwitch)" == "start" ]; then
[176]223    echo "$Tomcat_HOME/bin/startup.sh"
224    $Tomcat_HOME/bin/startup.sh
[162]225elif [ "$(cat $tomcatSwitch)" == "stop" ]; then
[176]226    echo "$Tomcat_HOME/bin/shutdown.sh"
227    $Tomcat_HOME/bin/shutdown.sh
[162]228elif [ "$(cat $tomcatSwitch)" == "restart" ]; then
[176]229    echo "$Tomcat_HOME/bin/restart.sh"
230    $Tomcat_HOME/bin/shutdown.sh
231    $Tomcat_HOME/bin/startup.sh
[162]232else
233    exit 0
234fi
235}
236
[172]237## [Tomcat Port Change] ##
[162]238function tomcat_port(){
239
[176]240if [ ! -e $Tomcat_HOME/conf/server.xml ]; then
[165]241    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Servel.xml]" \
[176]242        --msgbox "Fial: Don't find $Tomcat_HOME/conf/server.xml !!!" 10 50
[162]243    exit
244fi
245tomcatPort="/tmp/tomcatPort"
[165]246$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC  = " --title "[Tomcat Port Change]" \
[162]247    --inputbox "Plz input port number for tomcat (default is 8080)" 10 55 2>$tomcatPort
248
[177]249if [ -z "$(cat $tomcatPort)" ]; then
[162]250    exit
251else
[176]252    modify_line_nu=$(cat -n $Tomcat_HOME/conf/server.xml | grep -v SSL | grep 'HTTP/1.1' | grep '<Connector' | awk '{print $1}')
[182]253    sed -i "${modify_line_nu}c <Connector port=\"$(cat $tomcatPort)\" protocol=\"HTTP/1.1\"" $Tomcat_HOME/conf/server.xml
[176]254    $Tomcat_HOME/bin/shutdown.sh
255    $Tomcat_HOME/bin/startup.sh
[162]256fi
[176]257
258
[162]259}
260
261
[172]262## [Language Change] ##
[162]263function lang_switch(){
264echo -e "lang_switch"
265langSwitch="/tmp/langSwitch"
[165]266$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC  =" --title "[Language Swaitch]" \
[162]267    --menu "Plz choose: " 15 55 3 \
268    "English" "English" \
[177]269    "Chinese" "Chinese" \
270    "Exit" "Exit" 2>$langSwitch
[162]271#
[177]272if [ "$(cat $langSwitch)" == "Exit" ]; then
273    exit
274else
275    echo "source $(cat $langSwitch)"
276fi
[162]277}
278
279
[172]280# [Main Code] #
[162]281if [ $USER != "nutchuser" ]; then
282    echo -e "\nYour identify is not nutchuser, plz change to \"nutchuser\" !!!"
283    exit
284fi
285
286prepare_check
287main_menu
288case $(cat $main_choice) in
[174]289    "cluster_status")
290        cluster_status;;
[162]291    "cluster_setup")
292        cluster_setup;;
293    "tomcat_switch")
294        tomcat_switch;;
295    "tomcat_port")
296        tomcat_port;;
297    "lang_switch")
298        lang_switch;;
299esac
Note: See TracBrowser for help on using the repository browser.