[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 # |
---|
| 12 | DIALOG=dialog |
---|
| 13 | main_choice= |
---|
| 14 | #LIST_Option="off" |
---|
| 15 | |
---|
| 16 | # Functions Declaration # |
---|
| 17 | ## Prepare Check ## |
---|
| 18 | function prepare_check(){ |
---|
| 19 | if [ ! -e /home/nutchuser/nutch_nodes ]; then |
---|
[165] | 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 |
---|
[162] | 22 | exit |
---|
| 23 | fi |
---|
| 24 | |
---|
[165] | 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 |
---|
[162] | 27 | |
---|
[165] | 28 | |
---|
[162] | 29 | if [ "$?" == "0" ]; then |
---|
| 30 | ./duplicate_del /home/nutchuser/nutch_nodes |
---|
[165] | 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" |
---|
[162] | 33 | fi |
---|
| 34 | |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | ## Main Menu |
---|
| 38 | function main_menu(){ |
---|
| 39 | main_choice="/tmp/main_choice" |
---|
| 40 | |
---|
| 41 | $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" \ |
---|
[165] | 42 | --title "[Management Options]" \ |
---|
[162] | 43 | --menu "Plz choose: " 15 55 5 \ |
---|
[165] | 44 | "cluster_setup" "Setup your datanode & tasktracker" \ |
---|
[162] | 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 | |
---|
[165] | 51 | ## Cluster Setup (datanode & tasktracker) ## |
---|
[162] | 52 | function cluster_setup(){ |
---|
| 53 | |
---|
| 54 | node_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 |
---|
| 61 | clusterSetup="/tmp/clusterSetup" |
---|
[165] | 62 | $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Datanode & Tasktracker Setup]" \ |
---|
[162] | 63 | --menu "Plz choose: " 10 65 3 \ |
---|
[165] | 64 | "start" "Start all datanodes & tasktrackers in cluster" \ |
---|
| 65 | "stop" "Stop all datanodes & tasktrackers in cluster" \ |
---|
[162] | 66 | "exit" "Exit" 2>$clusterSetup |
---|
| 67 | |
---|
| 68 | #echo -e "$clusterSetup" |
---|
| 69 | |
---|
| 70 | if [ "$(cat $clusterSetup)" == "start" ]; then |
---|
| 71 | echo "/opt/nutchez/nutch/bin/hadoop-daemon.sh start datanode" |
---|
[165] | 72 | echo "/opt/nutchez/nutch/bin/hadoop-daemon.sh start tasktracker" |
---|
[162] | 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 |
---|
[165] | 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" |
---|
[162] | 81 | done |
---|
| 82 | elif [ "$(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 |
---|
[165] | 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" |
---|
[162] | 93 | done |
---|
| 94 | else |
---|
| 95 | exit 0 |
---|
| 96 | fi |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | ## Tomcat Severice start/stop/restart ## |
---|
| 100 | function tomcat_switch(){ |
---|
| 101 | pid_tc=$(ps axw -eo pid,command | grep "catalina" | grep "java" | grep "start" | awk '{print $1}') |
---|
| 102 | #echo $pid_tc |
---|
| 103 | #read |
---|
| 104 | if [ -n "$pid_tc" ]; then |
---|
[165] | 105 | $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \ |
---|
| 106 | --msgbox "Tomcat is runing in this system !!!" 7 50 |
---|
[162] | 107 | else |
---|
[165] | 108 | $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \ |
---|
| 109 | --msgbox "Tomcat is not running in this system !!!" 7 50 |
---|
[162] | 110 | fi |
---|
| 111 | tomcatSwitch="/tmp/tomcatSwitch" |
---|
[165] | 112 | $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Service Options]" \ |
---|
[162] | 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 | |
---|
| 119 | if [ "$(cat $tomcatSwitch)" == "start" ]; then |
---|
| 120 | echo "/opt/nutchez/tomcat/bin/startup.sh" |
---|
| 121 | /opt/nutchez/tomcat/bin/startup.sh |
---|
| 122 | elif [ "$(cat $tomcatSwitch)" == "stop" ]; then |
---|
| 123 | echo "/opt/nutchez/tomcat/bin/shutdown.sh" |
---|
| 124 | /opt/nutchez/tomcat/bin/shutdown.sh |
---|
| 125 | elif [ "$(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 |
---|
| 129 | else |
---|
| 130 | exit 0 |
---|
| 131 | fi |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | ## Tomcat Port change ## |
---|
| 135 | function tomcat_port(){ |
---|
| 136 | |
---|
| 137 | if [ ! -e /opt/nutchez/tomcat/conf/server.xml ]; then |
---|
[165] | 138 | $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Servel.xml]" \ |
---|
[162] | 139 | --msgbox "Fial: Don't find /opt/nutchez/tomcat/conf/server.xml !!!" 10 50 |
---|
| 140 | exit |
---|
| 141 | fi |
---|
| 142 | tomcatPort="/tmp/tomcatPort" |
---|
[165] | 143 | $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC = " --title "[Tomcat Port Change]" \ |
---|
[162] | 144 | --inputbox "Plz input port number for tomcat (default is 8080)" 10 55 2>$tomcatPort |
---|
| 145 | |
---|
| 146 | if [ -z $(cat $tomcatPort) ]; then |
---|
| 147 | exit |
---|
| 148 | else |
---|
| 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 |
---|
| 151 | fi |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | ## Language Change ## |
---|
| 156 | function lang_switch(){ |
---|
| 157 | echo -e "lang_switch" |
---|
| 158 | langSwitch="/tmp/langSwitch" |
---|
[165] | 159 | $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Language Swaitch]" \ |
---|
[162] | 160 | --menu "Plz choose: " 15 55 3 \ |
---|
| 161 | "English" "English" \ |
---|
| 162 | "Chinese" "Chinese" 2>$langSwitch |
---|
| 163 | # |
---|
| 164 | echo "source $(cat $langSwitch)" |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | |
---|
| 168 | # Main Code |
---|
| 169 | if [ $USER != "nutchuser" ]; then |
---|
| 170 | echo -e "\nYour identify is not nutchuser, plz change to \"nutchuser\" !!!" |
---|
| 171 | exit |
---|
| 172 | fi |
---|
| 173 | |
---|
| 174 | prepare_check |
---|
| 175 | main_menu |
---|
| 176 | case $(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;; |
---|
| 185 | esac |
---|