Changeset 186 for nutchez-0.2/src/test/nutchez
- Timestamp:
- Jun 14, 2010, 2:29:25 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
nutchez-0.2/src/test/nutchez
r185 r186 10 10 11 11 # [Variables Declaration] # 12 DIALOG= dialog12 DIALOG="dialog" 13 13 main_choice= 14 lang= 14 15 15 16 # [PATH Declaration] # 16 NutchEZ_Install_PATH=/opt/nutchez 17 Tomcat_HOME=/opt/nutchez/tomcat 18 NutchEZ_HOME=/home/nutchuser/nutchez 17 NutchEZ_Install_PATH="/opt/nutchez" 18 Tomcat_HOME="/opt/nutchez/tomcat" 19 NutchEZ_HOME="/home/nutchuser/nutchez" 20 21 # [Env Declaration] # 22 . lang_en_US_nutchez 19 23 20 24 # [Functions Declaration] # 21 ## [Prepare Check] ## 25 ## [Pre-check for language] ## 26 function prepare_lang(){ 27 lang=$(locale | grep 'LANG=' | cut -d "=" -f2) 28 29 # if lang=zh then source lang_zh_TW_nutchez 30 echo $lang | grep 'zh' && source lang_zh_TW_nutchez 31 } 32 33 34 ## [Pre-Check for nutch_nodes file] ## 22 35 function prepare_check(){ 23 36 # 若無 nutchez_nodes 則跳出 24 37 if [ ! -e "${NutchEZ_HOME}/system/nutch_nodes" ]; then 25 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" --title "[nutch_nodes Files]" \26 --msgbox " Fail: Don't find$NutchEZ_HOME/system/nutch_nodes !!!" 10 4038 $DIALOG --clear --backtitle "$dia_back" --title "$dia_pre_check_title_1" \ 39 --msgbox "$dia_pre_check_msg_1 $NutchEZ_HOME/system/nutch_nodes !!!" 10 40 27 40 exit 28 41 fi … … 31 44 # 第一次執行則要求 user 更新 /etc/hosts 32 45 if [ ! -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 5535 36 echo -e " Plz input root password to update /etc/hosts !!!"46 $DIALOG --clear --backtitle "$dia_back" --title "$dia_pre_check_title_2" \ 47 --yesno "$dia_pre_check_yesno_1\n$dia_pre_check_yesno_2" 10 55 48 49 echo -e "$pre_check_echo_1" 37 50 ./duplicate_del "${NutchEZ_HOME}/system/nutch_nodes" 38 51 su root -c "./duplicate_del /etc/hosts && ./add_hosts ${NutchEZ_HOME}/system/nutch_nodes /etc/hosts" 39 52 # 若密碼輸入失敗則跳出 40 53 if [ $? == "1" ]; then 41 echo " Root password is error ! Plz check root password !!!"54 echo "$pre_check_echo_2" 42 55 exit 43 56 fi 44 57 # 若 nutch_nodes 被更新過,則要求更新 /etc/hosts 45 58 elif [ ${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 5548 49 echo -e " Plz input root password to update /etc/hosts !!!"59 $DIALOG --clear --backtitle "$dia_back" --title "$dia_pre_check_title_2" \ 60 --yesno "$dia_pre_check_yesno_3\n$dia_pre_check_yesno_2" 10 55 61 62 echo -e "$pre_check_echo_1" 50 63 ./duplicate_del "${NutchEZ_HOME}/system/nutch_nodes" 51 64 su root -c "./duplicate_del /etc/hosts && ./add_hosts ${NutchEZ_HOME}/system/nutch_nodes /etc/hosts" 52 65 # 若密碼輸入失敗則跳出 53 66 if [ $? == "1" ]; then 54 echo " Root password is error ! Plz check root password !!!"67 echo "$pre_check_echo_2=" 55 68 exit 56 69 fi … … 62 75 main_choice="/tmp/main_choice" 63 76 64 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" \65 --title " [Management Options]" \66 --menu " Plz choose:" 15 60 7 \67 "cluster_status" " Check cluster status" \68 " server_setup" "Setup namenode & jobtracker" \69 " cluster_setup" "Setup datanode & tasktracker" \70 "tomcat_switch" " Start/Stop/Restart Tomcat" \71 "tomcat_port" " Change Tomcat port" \72 "lang_switch" " Change language" \73 "exit" " Exit" 2>$main_choice77 $DIALOG --clear --backtitle "$dia_back" \ 78 --title "$dia_main_title_1" \ 79 --menu "$dia_choose" 15 60 7 \ 80 "cluster_status" "$dia_main_menu_1_1" \ 81 "cluster_setup" "$dia_main_menu_1_2" \ 82 "server_setup" "$dia_main_menu_1_3" \ 83 "tomcat_switch" "$dia_main_menu_1_4" \ 84 "tomcat_port" "$dia_main_menu_1_5" \ 85 "lang_switch" "$dia_main_menu_1_6" \ 86 "exit" "$dia_exit" 2>$main_choice 74 87 } 75 88 … … 80 93 rm $clusterStatus 2> /dev/null 81 94 #printf '%16s\t %11s\t %10s\t %25s\n' "[IP] [Hostanme] [Network] [Dtatnode & Tasktracker]" >>$clusterStatus 82 echo -e " [IP] \t\t [Hostname] \t [Network] \t [Dtatnode & Tasktracker]" >>$clusterStatus95 echo -e "$cluster_status_echo_1" >>$clusterStatus 83 96 echo -e "------------------------------------------------------------------------" >>$clusterStatus 84 echo -e "\n Start to check cluster..."97 echo -e "\n$cluster_status_echo_2" 85 98 for ip in $IP_list 86 99 do … … 94 107 fi 95 108 96 # if [ $? == "255" ]; then97 # echo -e "$ip Network is down"98 # elif [ $? == "1" ]; then99 # echo -e "Can't ssh to $ip"100 # fi101 102 109 [ -z "$Task_Data" ] || Task_Data_status="running" 103 110 host_name=$(cat $NutchEZ_HOME/system/nutch_nodes | grep $ip | awk '{print $2}') 104 echo 111 echo -e "$ip $host_name \t\t $ip_status \t $Task_Data_status" >>$clusterStatus 105 112 # printf '%16s\t %11s\t %10s\t %25s\n' "$ip $host_name $ip_status $Task_Data_status" >>$clusterStatus 106 113 done 107 114 108 read -p " Plz input anykey to continue..."109 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" \110 --title " [Cluster Status]" --textbox $clusterStatus 20 90111 } 112 113 114 ## [ Cluster Setup (namenode & jobtracker)] ##115 read -p "$cluster_status_read_1" 116 $DIALOG --clear --backtitle "$dia_back" \ 117 --title "$dia_cluster_status_title_1" --textbox $clusterStatus 20 90 118 } 119 120 121 ## [Server Setup (namenode & jobtracker)] ## 115 122 function server_setup(){ 116 123 serverSetup=/tmp/serverSetup … … 119 126 120 127 if [ -z "$pid_name" -a -z "$pid_job" ]; then 121 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" --title "[Server Status]" \122 --msgbox " Namenode & Jobtracker are not running" 7 50128 $DIALOG --clear --backtitle "$dia_back" --title "$dia_server_title_1" \ 129 --msgbox "$dia_server_msg_1" 7 50 123 130 elif [ -z "$pid_name" -a -n "$pid_job" ]; then 124 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" --title "[Server Status]" \125 --msgbox " Jobtracker is running, Namenode is not running" 7 50131 $DIALOG --clear --backtitle "$dia_back" --title "$dia_server_title_1" \ 132 --msgbox "$dia_server_msg_2" 7 50 126 133 elif [ -n "$pid_name" -a -z "$pid_job" ]; then 127 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" --title "[Server Status]" \128 --msgbox " Namenode is running, Jobtracker is not running" 7 50129 else 130 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" --title "[Server Status]" \131 --msgbox " Namenode & Jobtracker are running" 7 50132 fi 133 134 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" --title "[Namenode & Jobtracker Setup]" \135 --menu " Plz choose:" 15 65 4 \136 "start" " Start namenode & jobtracker" \137 "stop" " Stop namenode & jobtracker" \138 "restart" " restart namenode & jobtracker" \139 "exit" " Exit" 2>$serverSetup134 $DIALOG --clear --backtitle "$dia_back" --title "$dia_server_title_1" \ 135 --msgbox "$dia_server_msg_3" 7 50 136 else 137 $DIALOG --clear --backtitle "$dia_back" --title "$dia_server_title_1" \ 138 --msgbox "$dia_server_msg_4" 7 50 139 fi 140 141 $DIALOG --clear --backtitle "$dia_back" --title "$dia_server_title_2" \ 142 --menu "$dia_choose" 15 65 4 \ 143 "start" "$dia_server_menu_1_1" \ 144 "stop" "$dia_server_menu_1_2" \ 145 "restart" "$dia_server_menu_1_3" \ 146 "exit" "$dia_exit" 2>$serverSetup 140 147 141 148 if [ "$(cat $serverSetup)" == "start" ]; then … … 153 160 exit 154 161 fi 155 156 157 162 } 158 163 … … 168 173 clusterSetup="/tmp/clusterSetup" 169 174 170 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" \171 --title " [Management Options]" \172 --menu " Plz choose:" 15 55 3 \173 "All" " All nodes" \174 "Part" " Choose part nodess" \175 "Exit" " Exit" 2>$allpart175 $DIALOG --clear --backtitle "$dia_back" \ 176 --title "$dia_cluster_setup_title_1" \ 177 --menu "$dia_choose" 15 55 3 \ 178 "All" "$dia_cluster_setup_menu_1_1" \ 179 "Part" "$dia_cluster_setup_menu_1_2" \ 180 "Exit" "$dia_exit" 2>$allpart 176 181 177 182 # 判斷是否選 all 和 part,若是 all 直接到服務選單,若是 part 則先到機器選單 … … 179 184 cat $NutchEZ_HOME/system/nutch_nodes | grep -v '^$' | grep -v '#' | awk '{print $1}' >$runNodes 180 185 elif [ "$(cat $allpart)" == "Part" ]; then 181 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC = " --title "[Datanode & Tasktracker Nodes Choose]" \182 --checklist " datanode & tasktracker choose:" 15 55 7 $(cat $NutchEZ_HOME/system/nutch_nodes | \186 $DIALOG --clear --backtitle "$dia_back" --title "$dia_cluster_setup_title_2" \ 187 --checklist "$dia_cluster_setup_check_1" 15 55 7 $(cat $NutchEZ_HOME/system/nutch_nodes | \ 183 188 grep -v '^$' | grep -v '#' | awk '{print $1 "\t" $2 "\t" "$LIST_status" }') 2>$runNodes 184 189 else … … 192 197 fi 193 198 194 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" --title "[Datanode & Tasktracker Setup]" \195 --menu " Plz choose:" 15 65 4 \196 "start" " Start datanodes & tasktrackers" \197 "stop" " Stop datanodes & tasktrackers" \198 "restart" " restart datanodes & tasktrackers" \199 "exit" " Exit" 2>$clusterSetup199 $DIALOG --clear --backtitle "$dia_back" --title "$dia_cluster_setup_title_3" \ 200 --menu "$dia_choose" 15 65 4 \ 201 "start" "$dia_cluster_setup_menu_2_1" \ 202 "stop" "$dia_cluster_setup_menu_2_2" \ 203 "restart" "$dia_cluster_setup_menu_2_3" \ 204 "exit" "$dia_exit" 2>$clusterSetup 200 205 201 206 if [ "$(cat $clusterSetup)" == "start" ]; then 202 echo -e "\n[Start datanode & tasktracker]" 207 echo -e "\n$cluster_setup_echo_1" 208 for node in $(cat $runNodes) 209 do 210 ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start datanode \ 211 ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start tasktracker" 2>/dev/null 212 [ $? == "0" ] || echo "$cluster_setup_echo_error $node !!!" 213 done 214 elif [ "$(cat $clusterSetup)" == "stop" ]; then 215 echo -e "\n$cluster_setup_echo_3" 203 216 for node in $(cat $runNodes) 204 217 do 205 echo -e "start $node datanode & tasktracker !"206 ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start datanode \207 ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start tasktracker"208 [ $? == "0" ] || echo "Can't ssh to $node !!!"209 done210 elif [ "$(cat $clusterSetup)" == "stop" ]; then211 echo -e "\n[Stop datanode & tasktracker]"212 for node in $(cat $runNodes)213 do214 echo -e "stop $node datanode & tasktracker !"215 218 ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop datanode \ 216 ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop tasktracker" 217 [ $? == "0" ] || echo " Can't ssh to$node !!!"219 ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop tasktracker" 2>/dev/null 220 [ $? == "0" ] || echo "$cluster_setup_echo_error $node !!!" 218 221 done 219 222 elif [ "$(cat $clusterSetup)" == "restart" ]; then 220 echo -e "\n [Restart datanode & tasktracker]"223 echo -e "\n$cluster_setup_echo_5" 221 224 for node in $(cat $runNodes) 222 225 do 223 echo -e "restart $node datanode & tasktracker !"224 226 ssh -o StrictHostKeyChecking=no $node "$NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop datanode \ 225 227 ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh stop tasktracker \ 226 228 ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start datanode \ 227 ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start tasktracker" 228 [ $? == "0" ] || echo " Can't ssh to$node !!!"229 ; $NutchEZ_Install_PATH/nutch/bin/hadoop-daemon.sh start tasktracker" 2>/dev/null 230 [ $? == "0" ] || echo "$cluster_setup_echo_error $node !!!" 229 231 done 230 232 else … … 235 237 ## [Tomcat Severice start/stop/restart] ## 236 238 function tomcat_switch(){ 237 pid_tc=$(ps axw -eo pid,command | grep "catalina" | grep "java" | grep "start" | awk '{print $1}') 238 #echo $pid_tc 239 #read 240 if [ -n "$pid_tc" ]; then 241 $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \ 242 --msgbox "Tomcat is runing in this system !!!" 7 50 243 else 244 $DIALOG --clear --backtitle "= [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Status]" \ 245 --msgbox "Tomcat is not running in this system !!!" 7 50 239 tom_pids=$(ps x | grep -v 'grep' | grep "tomcat" | awk '{print $1}') 240 if [ -n "$tom_pids" ]; then 241 $DIALOG --clear --backtitle "$dia_back" --title "$dia_tomcat_switch_title_1" \ 242 --msgbox "$dia_tomcat_switch_msg_1" 7 50 243 else 244 $DIALOG --clear --backtitle "$dia_back" --title "$dia_tomcat_switch_title_1" \ 245 --msgbox "$dia_tomcat_switch_msg_2" 7 50 246 246 fi 247 247 tomcatSwitch="/tmp/tomcatSwitch" 248 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Service Options]" \249 --menu " Plz choose:" 15 55 4 \250 "start" " Start tomcat" \251 "stop" " Stop tomcat" \252 "restart" " Restart tomcat" \253 "exit" " Exit" 2>$tomcatSwitch248 $DIALOG --clear --backtitle "$dia_back" --title "$dia_tomcat_switch_title_2" \ 249 --menu "$dia_choose" 15 55 4 \ 250 "start" "$dia_tomcat_switch_menu_1_1" \ 251 "stop" "$dia_tomcat_switch_menu_1_2" \ 252 "restart" "$dia_tomcat_switch_menu_1_3" \ 253 "exit" "$dia_exit" 2>$tomcatSwitch 254 254 255 255 if [ "$(cat $tomcatSwitch)" == "exit" ]; then … … 259 259 # jude $Tomcat_HOME/bin/startup.sh 260 260 if [ ! -e $Tomcat_HOME/bin/startup.sh ]; then 261 echo -e "\n Don't fine$Tomcat_HOME/bin/startup.sh"261 echo -e "\n$tomcat_switch_echo_1 $Tomcat_HOME/bin/startup.sh" 262 262 exit 263 263 fi 264 264 265 265 if [ ! -e $Tomcat_HOME/bin/shutdown.sh ]; then 266 echo -e "\n Don't fine$Tomcat_HOME/bin/shutdown.sh"266 echo -e "\n$tomcat_switch_echo_1 $Tomcat_HOME/bin/shutdown.sh" 267 267 exit 268 268 fi 269 269 270 270 if [ "$(cat $tomcatSwitch)" == "start" ]; then 271 echo " [Start Tomcat]"271 echo "$tomcat_switch_echo_3" 272 272 $Tomcat_HOME/bin/startup.sh 273 273 elif [ "$(cat $tomcatSwitch)" == "stop" ]; then 274 echo " [Stop Tomcat]"274 echo "$tomcat_switch_echo_4" 275 275 $Tomcat_HOME/bin/shutdown.sh 276 for tom_pid in $tom_pids 277 do 278 kill -9 $tom_pid 2>/dev/null 279 done 276 280 elif [ "$(cat $tomcatSwitch)" == "restart" ]; then 277 echo " [Restart Tomcat]"281 echo "$tomcat_switch_echo_5" 278 282 $Tomcat_HOME/bin/shutdown.sh 283 for tom_pid in $tom_pids 284 do 285 kill -9 $tom_pid 2>/dev/null 286 done 279 287 $Tomcat_HOME/bin/startup.sh 280 288 else … … 287 295 288 296 if [ ! -e $Tomcat_HOME/conf/server.xml ]; then 289 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" --title "[Tomcat Servel.xml]" \290 --msgbox " Fial: Don't find$Tomcat_HOME/conf/server.xml !!!" 10 50297 $DIALOG --clear --backtitle "$dia_back" --title "$dia_tomcat_port_title_1" \ 298 --msgbox "$dia_tomcat_port_msg_1 $Tomcat_HOME/conf/server.xml !!!" 10 50 291 299 exit 292 300 fi 293 301 tomcatPort="/tmp/tomcatPort" 294 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC = " --title "[Tomcat Port Change]" \295 --inputbox " Plz input port number for tomcat (default is 8080)" 10 55 2>$tomcatPort302 $DIALOG --clear --backtitle "$dia_back" --title "$dia_tomcat_port_title_2" \ 303 --inputbox "$dia_tomcat_port_input_1" 10 55 2>$tomcatPort 296 304 297 305 if [ -z "$(cat $tomcatPort)" ]; then … … 300 308 modify_line_nu=$(cat -n $Tomcat_HOME/conf/server.xml | grep -v SSL | grep 'HTTP/1.1' | grep '<Connector' | awk '{print $1}') 301 309 sed -i "${modify_line_nu}c <Connector port=\"$(cat $tomcatPort)\" protocol=\"HTTP/1.1\"" $Tomcat_HOME/conf/server.xml 310 311 tom_pids=$(ps x | grep -v 'grep' | grep "tomcat" | awk '{print $1}') 302 312 $Tomcat_HOME/bin/shutdown.sh 313 for tom_pid in $tom_pids 314 do 315 kill -9 $tom_pid 2>/dev/null 316 done 303 317 $Tomcat_HOME/bin/startup.sh 304 318 fi 305 306 307 319 } 308 320 … … 310 322 ## [Language Change] ## 311 323 function lang_switch(){ 312 echo -e "lang_switch"313 324 langSwitch="/tmp/langSwitch" 314 $DIALOG --clear --backtitle " = [NutchEz Management Interface] ~by NCHC =" --title "[Language Swaitch]" \315 --menu " Plz choose:" 15 55 3 \316 " English" "English" \317 " Chinese" "Chinese" \318 "Exit" " Exit" 2>$langSwitch325 $DIALOG --clear --backtitle "$dia_back" --title "$dia_lang_title_1" \ 326 --menu "$dia_choose" 15 55 3 \ 327 "en_US" "$dia_lang_menu_1_1" \ 328 "zh_TW" "$dia_lang_menu_1_2" \ 329 "Exit" "$dia_exit" 2>$langSwitch 319 330 # 320 331 if [ "$(cat $langSwitch)" == "Exit" ]; then 321 332 exit 322 else 323 echo "source $(cat $langSwitch)" 324 fi 325 } 326 327 328 # [Main Code] # 329 if [ $USER != "nutchuser" ]; then 330 echo -e "\nYour identify is not nutchuser, plz change to \"nutchuser\" !!!" 331 exit 332 fi 333 334 prepare_check 335 main_menu 333 elif [ "$(cat $langSwitch)" == "en_US" ]; then 334 source lang_en_US_nutchez 335 main_menu 336 menu_choose 337 elif [ "$(cat $langSwitch)" == "zh_TW" ]; then 338 source lang_zh_TW_nutchez 339 main_menu 340 menu_choose 341 fi 342 } 343 344 ## [Menu_choose] ## 345 function menu_choose(){ 336 346 case $(cat $main_choice) in 337 347 "cluster_status") 338 348 cluster_status;; 349 "cluster_setup") 350 cluster_setup;; 339 351 "server_setup") 340 352 server_setup;; 341 "cluster_setup")342 cluster_setup;;343 353 "tomcat_switch") 344 354 tomcat_switch;; … … 348 358 lang_switch;; 349 359 esac 360 } 361 362 # [Main Code] # 363 if [ $USER != "nutchuser" ]; then 364 echo -e "\n$user_error" 365 exit 366 fi 367 368 prepare_lang 369 prepare_check 370 main_menu 371 menu_choose
Note: See TracChangeset
for help on using the changeset viewer.