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

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

管理介面初版完成

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