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

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

修改nutch_node path(/home/nutchuser/nutchez/system/nutch_node)

File size: 6.8 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
11# Variables Declaration #
12DIALOG=dialog
13main_choice=
14#LIST_Option="off"
15
[171]16# PATH Declaration
17NutchEZ_Install_PATH=/opt/nutchez
18NutchEZ_HOME=/home/nutchuser/nutchez
19
[162]20# Functions Declaration #
21## Prepare Check  ##
22function prepare_check(){ 
[171]23if [ ! -e $NutchEZ_HOME/system/nutch_nodes ]; then
[165]24    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[nutch_nodes Files]" \
[171]25    --msgbox "Fail: Don't find $NutchEZ_Source_HOME/nutch_nodes !!!" 10 40
[162]26    exit
27fi
28
[165]29$DIALOG --clear --defaultno --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[/etc/host Update]" \
30    --yesno "Do you want to update \"/etc/hosts\" !!!\n(First time to execute it, please update)" 6 50
[162]31
[165]32
[162]33 if [ "$?" == "0" ]; then
[171]34    ./duplicate_del $NutchEZ_HOME/system/nutch_nodes
[165]35    echo -e "\nPlz input root password to update /etc/hosts !!!"
[171]36    su root -c "./duplicate_del /etc/hosts && ./add_hosts $NutchEZ_HOME/nutch_nodes /etc/hosts"
[162]37 fi
38}
39
40## Main Menu
41function main_menu(){
42main_choice="/tmp/main_choice"
43
44$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" \
[165]45    --title "[Management Options]" \
[162]46        --menu "Plz choose: " 15 55 5 \
[165]47        "cluster_setup" "Setup your datanode & tasktracker" \
[162]48        "tomcat_switch" "Start/Stop/Restart Tomcat" \
49        "tomcat_port" "Change Tomcat port" \
50        "lang_switch" "Change language" \
51        "exit" "Exit" 2>$main_choice
52}
53
[165]54## Cluster Setup (datanode & tasktracker) ##
[162]55function cluster_setup(){
56
[171]57node_list=$(cat /home/nutchuser/nutchez/nutch_nodes | awk '{print $1}')
[162]58#echo -e $node_list
59#read
60
61#dataNodes=$($DIALOG --clear  --backtitle "= [NutchEz Management Interface] ~by NCHC  = " --title "datanode & tasknode setup" \
62#    --checklist "datanode & tasknode choose: " 15 55 7 $(cat /home/nutchuser/nutch_nodes | awk '{print $1 "\t" $2 "\t" "off" }'))
63#echo $dataNodes
64clusterSetup="/tmp/clusterSetup"
[165]65$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Datanode & Tasktracker Setup]" \
[162]66    --menu "Plz choose: " 10 65 3 \
[165]67    "start" "Start all datanodes & tasktrackers in cluster" \
68    "stop" "Stop all datanodes & tasktrackers in cluster" \
[162]69    "exit" "Exit" 2>$clusterSetup
70
71#echo -e "$clusterSetup" 
72
73if [ "$(cat $clusterSetup)" == "start" ]; then
74    echo "/opt/nutchez/nutch/bin/hadoop-daemon.sh start datanode"
[165]75    echo "/opt/nutchez/nutch/bin/hadoop-daemon.sh start tasktracker"
[162]76    /opt/nutchez/nutch/bin/hadoop-daemon.sh start datanode
77    /opt/nutchez/nutch/bin/hadoop-daemon.sh start tasktracker
78    for node in $(echo $node_list)
79    do
[165]80        echo -e "ssh -o StrictHostKeyChecking=no $node /opt/nutchez/nutch/bin/hadoop-daemon.sh start datanode"
[170]81        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh start datanode"
[165]82        echo -e "ssh -o StrictHostKeyChecking=no $node /opt/nutchez/nutch/bin/hadoop-daemon.sh start tasktracker"
[170]83        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh start tasktracker"
[162]84    done
85elif [ "$(cat $clusterSetup)" == "stop" ]; then
86    echo "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop datanode"
87    echo "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop tasktracker"
[170]88    /opt/nutchez/nutch/bin/hadoop-daemon.sh stop datanode
89    /opt/nutchez/nutch/bin/hadoop-daemon.sh stop tasktracker
[162]90    for node in $(echo $node_list)
91    do
[165]92        echo -e "ssh -o StrictHostKeyChecking=no $node /opt/nutchez/nutch/bin/hadoop-daemon.sh stop datanode"
[170]93        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop datanode"
[165]94        echo -e "ssh -o StrictHostKeyChecking=no $node /opt/nutchez/nutch/bin/hadoop-daemon.sh stop tasktracker"
[170]95        ssh -o StrictHostKeyChecking=no $node "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop tasktracker"
[162]96    done
97else
98    exit 0
99fi
100}
101
102## Tomcat Severice start/stop/restart  ##
103function tomcat_switch(){
104pid_tc=$(ps axw -eo pid,command | grep "catalina" | grep "java" | grep "start" | awk '{print $1}')
105#echo $pid_tc
106#read
107if [ -n "$pid_tc" ]; then
[165]108    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \
109        --msgbox "Tomcat is runing in this system !!!" 7 50
[162]110else
[165]111    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \
112        --msgbox "Tomcat is not running in this system !!!" 7 50
[162]113fi
114tomcatSwitch="/tmp/tomcatSwitch"
[165]115$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Service Options]" \
[162]116    --menu "Plz choose: " 15 55 4 \
117        "start" "Start tomcat" \
118        "stop" "Stop tomcat" \
119        "restart" "Restart tomcat" \
120        "exit" "Exit" 2>$tomcatSwitch
121
122if [ "$(cat $tomcatSwitch)" == "start" ]; then
123    echo "/opt/nutchez/tomcat/bin/startup.sh"
124    /opt/nutchez/tomcat/bin/startup.sh
125elif [ "$(cat $tomcatSwitch)" == "stop" ]; then
126    echo "/opt/nutchez/tomcat/bin/shutdown.sh"
127    /opt/nutchez/tomcat/bin/shutdown.sh
128elif [ "$(cat $tomcatSwitch)" == "restart" ]; then
129    echo "/opt/nutchez/tomcat/bin/restart.sh"
130    /opt/nutchez/tomcat/bin/shutdown.sh
131    /opt/nutchez/tomcat/bin/startup.sh
132else
133    exit 0
134fi
135}
136
137##  Tomcat Port change ##
138function tomcat_port(){
139
140if [ ! -e /opt/nutchez/tomcat/conf/server.xml ]; then
[165]141    $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Servel.xml]" \
[162]142        --msgbox "Fial: Don't find /opt/nutchez/tomcat/conf/server.xml !!!" 10 50
143    exit
144fi
145tomcatPort="/tmp/tomcatPort"
[165]146$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC  = " --title "[Tomcat Port Change]" \
[162]147    --inputbox "Plz input port number for tomcat (default is 8080)" 10 55 2>$tomcatPort
148
149if [ -z $(cat $tomcatPort) ]; then
150    exit
151else
152    modify_line_nu=$(cat -n /opt/nutchez/tomcat/conf/server.xml | grep -v SSL | grep 'HTTP/1.1' | grep '<Connector' | awk '{print $1}')
153    sed -i "${modify_line_nu}c <Connector port="$tomcatPort" protocol="HTTP/1.1"" /opt/nutchez/tomcat/conf/server.xml
154fi
155}
156
157
158## Language Change  ##
159function lang_switch(){
160echo -e "lang_switch"
161langSwitch="/tmp/langSwitch"
[165]162$DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC  =" --title "[Language Swaitch]" \
[162]163    --menu "Plz choose: " 15 55 3 \
164    "English" "English" \
165    "Chinese" "Chinese" 2>$langSwitch
166#
167echo "source $(cat $langSwitch)"
168}
169
170
171# Main Code
172if [ $USER != "nutchuser" ]; then
173    echo -e "\nYour identify is not nutchuser, plz change to \"nutchuser\" !!!"
174    exit
175fi
176
177prepare_check
178main_menu
179case $(cat $main_choice) in
180    "cluster_setup")
181        cluster_setup;;
182    "tomcat_switch")
183        tomcat_switch;;
184    "tomcat_port")
185        tomcat_port;;
186    "lang_switch")
187        lang_switch;;
188esac
Note: See TracBrowser for help on using the repository browser.