#!/bin/bash # Program: # NutchEz management interface # Author: # Waue, Shunfa, Rock {waue, shunfa, rock}@nchc.org.tw # Version: # 1.0 # History: # 2010/06/07 Rock First release (1.0) # [Variables Declaration] # DIALOG=dialog main_choice= # [PATH Declaration] # NutchEZ_Install_PATH=/opt/nutchez Tomcat_HOME=/opt/nutchez/tomcat NutchEZ_HOME=/home/nutchuser/nutchez # [Functions Declaration] # ## [Prepare Check] ## function prepare_check(){ # 若無 nutchez_nodes 則跳出 if [ ! -e "${NutchEZ_HOME}/system/nutch_nodes" ]; then $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[nutch_nodes Files]" \ --msgbox "Fail: Don't find $NutchEZ_HOME/system/nutch_nodes !!!" 10 40 exit fi # 判斷 nutch_nodes 和 nutch_nodes.back # 第一次執行則要求 user 更新 /etc/hosts if [ ! -e "${NutchEZ_HOME}/system/nutch_nodes.bak" ]; then $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[/etc/host Update]" \ --yesno "First execut nutchez management interface.\nPlz update /etc/hosts !!!" 10 55 echo -e "Plz input root password to update /etc/hosts !!!" ./duplicate_del "${NutchEZ_HOME}/system/nutch_nodes" su root -c "./duplicate_del /etc/hosts && ./add_hosts ${NutchEZ_HOME}/system/nutch_nodes /etc/hosts" # 若密碼輸入失敗則跳出 if [ $? == "1" ]; then echo "Root password is error ! Plz check root password !!!" exit fi # 若 nutch_nodes 被更新過,則要求更新 /etc/hosts elif [ ${NutchEZ_HOME}/system/nutch_nodes -nt ${NutchEZ_HOME}/system/nutch_nodes.bak ]; then $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[/etc/host Update]" \ --yesno "nutch_nodes already be modified.\nPlz update /etc/hosts !!!" 10 55 echo -e "Plz input root password to update /etc/hosts !!!" ./duplicate_del "${NutchEZ_HOME}/system/nutch_nodes" su root -c "./duplicate_del /etc/hosts && ./add_hosts ${NutchEZ_HOME}/system/nutch_nodes /etc/hosts" # 若密碼輸入失敗則跳出 if [ $? == "1" ]; then echo "Root password is error ! Plz check root password !!!" exit fi fi } ## [Main Menu] ## function main_menu(){ main_choice="/tmp/main_choice" $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" \ --title "[Management Options]" \ --menu "Plz choose: " 15 60 6 \ "cluster_status" "Check cluster status" \ "cluster_setup" "Setup your datanode & tasktracker" \ "tomcat_switch" "Start/Stop/Restart Tomcat" \ "tomcat_port" "Change Tomcat port" \ "lang_switch" "Change language" \ "exit" "Exit" 2>$main_choice } ## [Cluster Status (datanode & tasktracker)] ## function cluster_status(){ IP_list=$(cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#' | awk '{print $1}') clusterStatus="/tmp/clusterStatus" rm $clusterStatus 2> /dev/null #printf '%16s\t %11s\t %10s\t %25s\n' "[IP] [Hostanme] [Network] [Dtatnode & Tasktracker]" >>$clusterStatus echo -e "[IP] \t\t [Hostname] \t [Network] \t [Dtatnode & Tasktracker]" >>$clusterStatus echo -e "------------------------------------------------------------------------" >>$clusterStatus echo -e "\nStart to check cluster..." for ip in $IP_list do # Check Network status ip_status="online" ping -c1 -w1 $ip 2>&1 > /dev/null || ip_status="offline" # Check Hadoop/Nutch service through ssh Task_Data_status="stop" if [ $ip_status == "online" ]; then Task_Data=$(ssh -o StrictHostKeyChecking=no $ip "jps |grep TaskTracker ; jps | grep DataNode") fi # if [ $? == "255" ]; then # echo -e "$ip Network is down" # elif [ $? == "1" ]; then # echo -e "Can't ssh to $ip" # fi [ -z "$Task_Data" ] || Task_Data_status="running" host_name=$(cat $NutchEZ_HOME/system/nutch_nodes | grep $ip | awk '{print $2}') echo -e "$ip $host_name \t\t $ip_status \t $Task_Data_status" >>$clusterStatus # printf '%16s\t %11s\t %10s\t %25s\n' "$ip $host_name $ip_status $Task_Data_status" >>$clusterStatus done read -p "Plz input anykey to continue..." $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" \ --title "[Cluster Status]" --textbox $clusterStatus 20 90 } ## [Cluster Setup (datanode & tasktracker)] ## function cluster_setup(){ # 從 nutch_nodes 讀出 ip 和 hostname #IP_list=$(cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#' | awk '{print $1}') #HOST_list=$(cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#' | awk '{print $2}') LIST_status="off" allpart="/tmp/allpart" runNodes="/tmp/runNodes" clusterSetup="/tmp/clusterSetup" $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" \ --title "[Management Options]" \ --menu "Plz choose: " 15 55 3 \ "All" "All nodes" \ "Part" "Choose part nodess" \ "Exit" "Exit" 2>$allpart # 判斷是否選 all 和 part,若是 all 直接到服務選單,若是 part 則先到機器選單 if [ "$(cat $allpart)" == "All" ]; then cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#' | awk '{print $1}' >$runNodes elif [ "$(cat $allpart)" == "Part" ]; then $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC = " --title "[Datanode & Tasktracker Nodes Choose]" \ --checklist "datanode & tasktracker choose: " 15 55 7 $(cat $NutchEZ_HOME/system/nutch_nodes | \ grep -v '^$' | grep -v '#' | awk '{print $1 "\t" $2 "\t" "$LIST_status" }') 2>$runNodes else exit fi if [ -z "$(cat $runNodes)" ]; then exit fi $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Datanode & Tasktracker Setup]" \ --menu "Plz choose: " 15 65 4 \ "start" "Start datanodes & tasktrackers" \ "stop" "Stop datanodes & tasktrackers" \ "restart" "restart datanodes & tasktrackers" \ "exit" "Exit" 2>$clusterSetup if [ "$(cat $clusterSetup)" == "start" ]; then echo -e "\n[Start datanode & tasktracker]" for node in $(cat $runNodes) do echo -e "start $node datanode & tasktracker !" ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start datanode \ ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start tasktracker" [ $? == "0" ] || echo "Can't ssh to $node !!!" done elif [ "$(cat $clusterSetup)" == "stop" ]; then echo -e "\n[Stop datanode & tasktracker]" for node in $(cat $runNodes) do echo -e "stop $node datanode & tasktracker !" ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop datanode \ ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop tasktracker" [ $? == "0" ] || echo "Can't ssh to $node !!!" done elif [ "$(cat $clusterSetup)" == "restart" ]; then echo -e "\n[Restart datanode & tasktracker]" for node in $(cat $runNodes) do echo -e "restart $node datanode & tasktracker !" ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop datanode \ ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop tasktracker \ ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start datanode \ ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start tasktracker" [ $? == "0" ] || echo "Can't ssh to $node !!!" done else exit fi } ## [Tomcat Severice start/stop/restart] ## function tomcat_switch(){ pid_tc=$(ps axw -eo pid,command | grep "catalina" | grep "java" | grep "start" | awk '{print $1}') #echo $pid_tc #read if [ -n "$pid_tc" ]; then $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \ --msgbox "Tomcat is runing in this system !!!" 7 50 else $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \ --msgbox "Tomcat is not running in this system !!!" 7 50 fi tomcatSwitch="/tmp/tomcatSwitch" $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Service Options]" \ --menu "Plz choose: " 15 55 4 \ "start" "Start tomcat" \ "stop" "Stop tomcat" \ "restart" "Restart tomcat" \ "exit" "Exit" 2>$tomcatSwitch if [ "$(cat $tomcatSwitch)" == "exit" ]; then exit 0 fi # jude $Tomcat_HOME/bin/startup.sh if [ ! -e $Tomcat_HOME/bin/startup.sh ]; then echo -e "\nDon't fine $Tomcat_HOME/bin/startup.sh" exit fi if [ ! -e $Tomcat_HOME/bin/shudown.sh ]; then echo -e "\nDon't fine $Tomcat_HOME/bin/shudown.sh" exit fi if [ "$(cat $tomcatSwitch)" == "start" ]; then echo "$Tomcat_HOME/bin/startup.sh" $Tomcat_HOME/bin/startup.sh elif [ "$(cat $tomcatSwitch)" == "stop" ]; then echo "$Tomcat_HOME/bin/shutdown.sh" $Tomcat_HOME/bin/shutdown.sh elif [ "$(cat $tomcatSwitch)" == "restart" ]; then echo "$Tomcat_HOME/bin/restart.sh" $Tomcat_HOME/bin/shutdown.sh $Tomcat_HOME/bin/startup.sh else exit 0 fi } ## [Tomcat Port Change] ## function tomcat_port(){ if [ ! -e $Tomcat_HOME/conf/server.xml ]; then $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Servel.xml]" \ --msgbox "Fial: Don't find $Tomcat_HOME/conf/server.xml !!!" 10 50 exit fi tomcatPort="/tmp/tomcatPort" $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC = " --title "[Tomcat Port Change]" \ --inputbox "Plz input port number for tomcat (default is 8080)" 10 55 2>$tomcatPort if [ -z "$(cat $tomcatPort)" ]; then exit else modify_line_nu=$(cat -n $Tomcat_HOME/conf/server.xml | grep -v SSL | grep 'HTTP/1.1' | grep '$langSwitch # if [ "$(cat $langSwitch)" == "Exit" ]; then exit else echo "source $(cat $langSwitch)" fi } # [Main Code] # if [ $USER != "nutchuser" ]; then echo -e "\nYour identify is not nutchuser, plz change to \"nutchuser\" !!!" exit fi prepare_check main_menu case $(cat $main_choice) in "cluster_status") cluster_status;; "cluster_setup") cluster_setup;; "tomcat_switch") tomcat_switch;; "tomcat_port") tomcat_port;; "lang_switch") lang_switch;; esac