• Apache Tomcat Manager 2.0


    Apache Tomcat Manager 2.0

    Abbr. atm


    Suitable for:
        Apache Tomcat 7.0.47


    96CEA91ACF2F9255AE9D161B420612FA  atm
    0856F3886B6CF0527E792ABE9764EF1A  atm.ini
    995F95A21622CFE94B3D6DDE00A25F19  atm.log

    默认会排序,可以通过执行多条命令来抑制,如:
    atm -m 2; atm -m 3; atm -m 1

    新增:WHEN/stopwatch/-v

    atm.ini

    1 # PRG_HOME_DIRS - program home directories, separated by ":"
    2 PRG_HOME_DIRS=/opt/data/devel/apache-tomcat-7.0.47/p54321:/opt/data/devel/apache-tomcat-7.0.47/p6666:/opt/data/devel/apache-tomcat-7.0.47/p80
    3 # Pause for NUMBER seconds. (e.g., 15/5/3)
    4 WHEN_KILL=0.3
    5 WHEN_FORCE_KILL=0.2
    6 WHEN_REVIEW=0.1
    7 #EOF

    atm.log

     1  Lap              Begin                End        Duration     Duration (HRF) Message
     2    1 13:44:19.496921725 13:44:19.507952040     0.011030315 00:00:00.011030315 Deal with 'ccms'.
     3    2 13:44:19.507952040 13:44:19.542371298     0.034419258 00:00:00.034419258 Remove file.
     4    3 13:44:19.542371298 13:44:19.647810494     0.105439196 00:00:00.105439196 Copy file.
     5    4 13:44:19.647810494 13:44:19.656263875     0.008453381 00:00:00.008453381 Deal with 'df-1'.
     6    5 13:44:19.656263875 13:44:19.682079662     0.025815787 00:00:00.025815787 Remove file.
     7    6 13:44:19.682079662 13:44:19.786467747     0.104388085 00:00:00.104388085 Copy file.
     8    7 13:44:19.786467747 13:44:19.794942150     0.008474403 00:00:00.008474403 Deal with 'df-2'.
     9    8 13:44:19.794942150 13:44:19.820843004     0.025900854 00:00:00.025900854 Remove file.
    10    9 13:44:19.820843004 13:44:19.926616600     0.105773596 00:00:00.105773596 Copy file.
    11   10 13:44:19.926616600 13:44:19.985710578     0.059093978 00:00:00.059093978 Starting '/opt/data/devel/apache-tomcat-7.0.47/p80'.
    12   11 13:44:19.985710578 13:44:20.002478496     0.012589872 00:00:00.012589872 * Last lap
    13     13:44:19.994237292 13:44:19.998415338     0.004178046 00:00:00.004178046 'Deploy' -> 'completed'
    14                                     Total:     0.016767918 00:00:00.016767918
    15 -----------------------------------------------------------------------------
    16                                   Summary:     0.505556771 00:00:00.505556771

    atm

      1 #!/bin/sh
      2 
      3 echo_n(){
      4     echo -e "33[30;32m$*33[0m"
      5 }
      6 
      7 echo_e(){
      8     echo -e "33[30;35m$*33[0m"
      9 }
     10 
     11 trim(){
     12     echo $1
     13 }
     14 
     15 is_contains(){
     16     local ps=
     17     for ps in $2; do
     18         if [ "$ps" = "$1" ]; then
     19             echo true
     20             return 1
     21         fi
     22     done
     23     echo false
     24 }
     25 
     26 chk_positive_integer(){
     27     POS_INT=
     28     local nstr=`trim "$1"`
     29     echo "$nstr" | grep "[^0-9]" >/dev/null 2>&1
     30     if [ $? -eq 1 ]&&[ ! -z "$nstr" ]; then
     31         local t=$(expr $nstr + 0)
     32         if (( $t > 0 )); then
     33             POS_INT=$t
     34             return 1
     35         fi
     36     fi
     37 }
     38 
     39 to_positive_integer(){
     40     chk_positive_integer "$1"
     41     echo $POS_INT
     42 }
     43 
     44 one_slash(){
     45     local str="$1"
     46     while [[ "$src" == *//* ]]; do
     47         local regex="//" repl="/"
     48         str="${str//$regex/$repl}"
     49     done
     50     echo $str
     51 }
     52 
     53 to_canonical_path(){
     54     local path=`trim "$1"`
     55     if [ ! -z "$path" ]&&[ -e "$path" ]; then
     56         local result=
     57         if [ -d "$path" ]; then
     58             result=`cd "$path"; pwd`
     59         elif [ -f "$path" ]; then
     60             local directory=`dirname "$path"`
     61             directory=`cd "$directory"; pwd`
     62             local filename=`basename "$path"`
     63             result="$directory/$filename"
     64         fi
     65         result=`one_slash "$result"`
     66         echo $result
     67     fi
     68 }
     69 
     70 display_time_its(){
     71     local internal_time_stamp="$1" format="$2" utc="$3"
     72     if [ ! -z "$internal_time_stamp" ]; then
     73         if [ "$format" = "" ]; then
     74             format="+%Y%m%d_%H%M%S_%N"
     75         elif [ "$format" = "datetime" ]; then
     76             format="+%Y%m%d%H%M%S"
     77         elif [ "$format" = "clock" ]; then
     78             format="+%F %T"
     79         elif [ "$format" = "date" ]; then
     80             format="+%Y%m%d"
     81         elif [ "$format" = "date-" ]; then
     82             format="+%F"
     83         elif [ "$format" = "time" ]; then
     84             format="+%H%M%S"
     85         elif [ "$format" = "time:" ]; then
     86             format="+%T"
     87         elif [ "$format" = "time:.ns" ]; then
     88             format="+%T.%N"
     89         elif [ "$format" = "clock.ns" ]; then
     90             format="+%F %T.%N"
     91         elif [ "$format" = "table" ]; then
     92             format="+%F%t%T%t%N"
     93         fi
     94         if [ -z "$utc" ]; then
     95             date -d @$internal_time_stamp "$format"
     96         else
     97             date -u -d @$internal_time_stamp "$format"
     98         fi
     99     fi
    100 }
    101 
    102 stopwatch(){
    103     local cmd="$1" msg="$2"
    104     if [ "$cmd" = "start" ]; then
    105         if [ "$sw_state" = "" ]; then
    106             unset sw_state sw_ref_arr sw_lap_begin sw_lap_end sw_lap_arr sw_pause_begin sw_pause_end sw_pause_arr sw_msg_idx sw_lap_msg_arr sw_pause_msg_idx sw_pause_msg_arr
    107             sw_lap_begin="`date +%s.%N`"
    108             sw_state="R"
    109             sw_lap_msg_idx=0
    110             sw_pause_msg_idx=0
    111             sw_pause_msg_arr[$sw_pause_msg_idx]="$msg"
    112         elif [ "$sw_state" = "H" ]; then
    113             sw_pause_end="`date +%s.%N`"
    114             sw_pause_arr[${#sw_pause_arr[*]}]="$sw_pause_begin-$sw_pause_end"
    115             sw_pause_msg_arr[$sw_pause_msg_idx]="$msg"
    116             sw_state="R"
    117         else
    118             echo_e "(Start) requires the state to be ''/'H'."
    119         fi
    120     elif [ "$cmd" = "lap" ]; then
    121         if [ "$sw_state" = "R" ]; then
    122             sw_lap_end="`date +%s.%N`"
    123             sw_lap_arr[${#sw_lap_arr[*]}]="$sw_lap_begin $sw_lap_end"
    124             sw_lap_begin="$sw_lap_end"
    125             sw_ref_arr[$(expr ${#sw_lap_arr[*]} - 1)]=${sw_pause_arr[*]}
    126             sw_pause_arr=()
    127             sw_lap_msg_arr[$sw_lap_msg_idx]="$msg"
    128             let "sw_lap_msg_idx+=1"
    129         else
    130             echo_e "(Lap) requires the state to be 'R'."
    131         fi
    132     elif [ "$cmd" = "stop" ]; then
    133         if [ "$sw_state" = "R" ]; then
    134             sw_pause_begin="`date +%s.%N`"
    135             sw_pause_msg_arr[$sw_pause_msg_idx]="'${sw_pause_msg_arr[$sw_pause_msg_idx]}' -> '$msg'"
    136             let "sw_pause_msg_idx+=1"
    137             sw_state="H"
    138         else
    139             echo_e "(Stop) requires the state to be 'R'."
    140         fi
    141     elif [ "$cmd" = "reset" ]; then
    142         if [ "$sw_state" = "H" ]; then
    143             stopwatch start "* Last start"
    144             stopwatch lap "* Last lap"
    145             stopwatch stop "* Last stop"
    146             sw_state=
    147         else
    148             echo_e "(Reset) requires the state to be 'H'."
    149         fi
    150     else
    151         if [ ! "$sw_state" = "" ]; then
    152             echo_e "(*) requires the state to be ''."
    153         elif [ ${#sw_lap_arr[*]} != 0 ]; then
    154             printf "%4s %18s %18s %15s %18s %s
    " "Lap" "Begin" "End" "Duration" "Duration (HRF)" "Message"
    155             local i= summary_exp=0 pause_msg_idx=0 lap_msg_idx=0
    156             for((i=0;i<${#sw_lap_arr[*]};i++)); do
    157                 local lap_item=(${sw_lap_arr[$i]})
    158                 local lap_dur_exp="${lap_item[1]} - ${lap_item[0]}"
    159                 local total_duration="`echo "$lap_dur_exp" | bc | awk '{ printf "%.9f
    ", $1 }'`"
    160                 local pause_arr=(${sw_ref_arr[$i]})
    161                 local pause_dur_arr=()
    162                 local j=
    163                 for((j=0;j<${#pause_arr[*]};j++)); do
    164                     local pause_item="${pause_arr[$j]}"
    165                     pause_item=(${pause_item//-/ })
    166                     pause_dur_arr[j]="`echo "${pause_item[1]} - ${pause_item[0]}" | bc | awk '{ printf "%.9f
    ", $1 }'`"
    167                     lap_dur_exp="$lap_dur_exp - ${pause_dur_arr[j]}"
    168                 done
    169                 local real_duration="`echo "$lap_dur_exp" | bc | awk '{ printf "%.9f
    ", $1 }'`"
    170                 printf "%4s %18s %18s %15s %18s %s
    " "$(expr $i + 1)" 
    171                 "`display_time_its ${lap_item[0]} time:.ns`" 
    172                 "`display_time_its ${lap_item[1]} time:.ns`" 
    173                 "$real_duration" 
    174                 "`display_time_its $real_duration time:.ns *`" 
    175                 "${sw_lap_msg_arr[$lap_msg_idx]}"
    176                 let "lap_msg_idx+=1"
    177                 for((j=0;j<${#pause_arr[*]};j++)); do
    178                     local pause_item="${pause_arr[$j]}"
    179                     pause_item=(${pause_item//-/ })
    180                     printf "%4s %18s %18s %15s %18s %s
    " "\" 
    181                     "`display_time_its ${pause_item[0]} time:.ns`" 
    182                     "`display_time_its ${pause_item[1]} time:.ns`" 
    183                     "${pause_dur_arr[j]}" 
    184                     "`display_time_its ${pause_dur_arr[j]} time:.ns *`" 
    185                     "${sw_pause_msg_arr[$pause_msg_idx]}"
    186                     let "pause_msg_idx+=1"
    187                 done
    188                 if [ $j != 0 ]; then
    189                     printf "%42s %15s %18s
    " "Total:" "$total_duration" "`display_time_its $total_duration time:.ns *`"
    190                     summary_exp="$summary_exp + $total_duration"
    191                 else
    192                     summary_exp="$summary_exp + $real_duration"
    193                 fi
    194             done
    195             local m=0
    196             while((m < 77)); do
    197                 printf "%s" "-"
    198                 let "m+=1"
    199             done
    200             printf "
    "
    201             local summary_val="`echo "$summary_exp" | bc | awk '{ printf "%.9f
    ", $1 }'`"
    202             printf "%42s %15s %18s
    " "Summary:" "$summary_val" "`display_time_its $summary_val time:.ns *`"
    203         else
    204             echo_e No data.
    205         fi
    206     fi
    207 }
    208 
    209 show_usage(){
    210     echo
    211     echo_n "Apache Tomcat Manager 1.0"
    212     echo_n "Report bugs to <614616185@qq.com>."
    213     echo
    214     echo "Usage: ${0##*/} [OPTION]..."
    215     printf "	%-8s%s
    " "-g" "Generate optimal 'PRG_HOME_DIRS'."
    216     printf "	%-8s%s
    " "-l" "List program home directories."
    217     printf "	%-8s%s
    " "-s" "Query program state."
    218     printf "		%-8s%s
    " "-h" "State is 'Halted'."
    219     printf "		%-8s%s
    " "-r" "State is 'Running'."
    220     printf "		%-8s%s
    " "-a" "State is 'Abnormal'."
    221     printf "		%-8s%s
    " "-ra" "State is 'Running' or 'Abnormal'."
    222     printf "	%-8s%s
    " "-d" "Diagnosing program state."
    223     printf "	%-8s%s
    " "-r" "Run program."
    224     printf "	%-8s%s
    " "-h" "Halt program."
    225     printf "	%-8s%s
    " "-k" "Kill program."
    226     printf "	%-8s%s
    " "-fk" "Force kill program."
    227     printf "	%-8s%s
    " "-m" "Monitoring log (Ctrl+)."
    228     printf "	%-8s%s
    " "-c" "Clean up the cache and garbage."
    229     printf "	%-8s%s
    " "-R" "Rerun program."
    230     printf "	%-8s%s
    " "-D" "Deploy web application archive."
    231     printf "	%-8s%s
    " "-v" "View recent executions."
    232     echo
    233 }
    234 
    235 chk_widest(){
    236     local i= max=0 arr=($1)
    237     for((i=0;i<${#arr[*]};i++)); do
    238         if [ ${#arr[$i]} -gt $max ]; then
    239             max=${#arr[$i]}
    240         fi
    241     done
    242     WIDEST=$max
    243 }
    244 
    245 is_prg_id(){
    246     if (( $phd_len > 0 )) && (( $1 >= 0 )) && (( $1 < $phd_len )); then
    247         echo true
    248     else
    249         echo false
    250     fi
    251 }
    252 
    253 chk_process(){
    254     pid_arr=() pid_str= pid_len=0
    255     local prg_path="${phd_arr[$1]}"
    256     if [ ! -z "$prg_path" ]; then
    257         local java_pids="`ps --no-heading -o pid -C java`"
    258         java_pids=`echo $java_pids`
    259         if [ ! -z "$java_pids" ]; then
    260             local prg_pids=`ps --no-heading -o pid,cmd -p $java_pids | grep $prg_path | awk '{ print $1 }'`
    261             pid_str=`echo $prg_pids`
    262             pid_arr=($pid_str)
    263             pid_len=${#pid_arr[*]}
    264         fi
    265     fi
    266 }
    267 
    268 chk_status(){
    269     local rtn=0 arr=("Not running" "OK" "Abnormal")
    270     chk_process $1
    271     rtn=$pid_len
    272     if [ $pid_len -gt 1 ]; then
    273         rtn=2
    274     fi
    275     STATE_LABEL=${arr[$rtn]}
    276     return $rtn
    277 }
    278 
    279 print_header(){
    280     printf "%4s	%11s	%${PHD_COL_W}s
    " "ID" "State" "Program Home Directory"
    281 }
    282 
    283 show_status(){
    284     if [ -z "$1" ]||`is_contains "$1" "-h -r -a -ra"`; then
    285         local i= t_body=
    286         for((i=0;i<$phd_len;i++)); do
    287             chk_status $i
    288             local rtn=$?
    289             if [ -z "$1" ] || [[ "$1" = "-h" && (( $rtn == 0 )) ]] || [[ "$1" = "-r" && (( $rtn == 1 )) ]] || [[ "$1" = "-a" && (( $rtn == 2 )) ]] || [[ "$1" = "-ra" && (( $rtn != 0 )) ]]; then
    290                 local t_tr=`printf "%4s	%11s	%-${PHD_COL_W}s
    " "$(expr $i + 1)" "$STATE_LABEL" "${phd_arr[$i]}"`
    291                 if [ -z "$t_body" ]; then
    292                     t_body="$t_tr
    "
    293                 else
    294                     t_body="$t_body$t_tr
    "
    295                 fi
    296             fi
    297         done
    298         if [ -z "$t_body" ]; then
    299             echo_e No data.
    300         else
    301             print_header
    302             echo -e "$t_body"
    303         fi
    304     else
    305         show_usage
    306         exit
    307     fi
    308 }
    309 
    310 exec_prg(){
    311     #local p
    312     #for p in "$@"; do
    313     #    echo [$p]
    314     #done
    315     local state_filter=
    316     if `is_contains "$1" "-r -c"`; then
    317         state_filter="-h"
    318     elif `is_contains "$1" "-h -m"`; then
    319         state_filter="-r"
    320     elif `is_contains "$1" "-d -k -fk"`; then
    321         state_filter="-ra"
    322     fi
    323     if [ $# -eq 1 ]; then
    324         local result="`show_status $state_filter`"
    325         echo "$result"
    326         if [ `echo "$result" | wc -l` -gt 1 ]; then
    327             echo -e "Examples:
    	${0##*/} $1 8 4 2 1..."
    328         fi
    329     else
    330         local opt1=$1 tmp_str=
    331         while [ $# -gt 1 ]; do
    332             local tpi=`to_positive_integer "$2"`
    333             if [ ! -z "$tpi" ]&&[ $tpi -le $phd_len ]; then
    334                 if [ -z "$tmp_str" ]; then
    335                     tmp_str=$tpi
    336                 else
    337                     tmp_str="$tmp_str $tpi"
    338                 fi
    339             fi
    340             shift
    341         done
    342         local id= idx= executed_idxs= diagnose_header=true
    343         for id in `echo -e "${tmp_str// /\n}" | sort -nu`; do
    344             idx=$(expr $id - 1)
    345             if `is_prg_id $idx`; then
    346                 chk_status $idx
    347                 local rtn=$?
    348                 if [ "$opt1" = "-R" ] || ( `is_contains "$opt1" "-c -r"` && (( $rtn == 0 )) ) || ( `is_contains "$opt1" "-h -m"` && (( $rtn == 1 )) ) || ( `is_contains "$opt1" "-d -k -fk"` && (( $rtn != 0 )) ); then
    349                     local cmd=
    350                     local phd=${phd_arr[$idx]}
    351                     if [ "$opt1" = "-r" ]; then
    352                         echo_n "Run ($id) '$phd'."
    353                         cmd="$phd/bin/startup.sh"
    354                     elif [ "$opt1" = "-h" ]; then
    355                         echo_n "Halt ($id) '$phd'."
    356                         cmd="$phd/bin/shutdown.sh"
    357                     elif [ "$opt1" = "-m" ]; then
    358                         echo_n "Monitoring ($id) '$phd'."
    359                         pushd $phd/logs >/dev/null 2>&1
    360                         tail -f catalina.out
    361                         popd >/dev/null 2>&1
    362                     elif [ "$opt1" = "-c" ]; then
    363                         echo_n "Clean up ($id) '$phd'."
    364                         echo -e "	--> logs"
    365                         pushd $phd/logs >/dev/null 2>&1
    366                         rm -rfv *
    367                         popd >/dev/null 2>&1
    368                         echo -e "	--> work"
    369                         pushd $phd/work >/dev/null 2>&1
    370                         rm -rfv *
    371                         popd >/dev/null 2>&1
    372                     elif [ "$opt1" = "-R" ]; then
    373                         echo_n "Rerun ($id) '$phd'."
    374                         if [ $rtn -eq 1 ]; then
    375                             echo_n "Shutting down..."
    376                             "$phd/bin/shutdown.sh" >/dev/null 2>&1
    377                             if [ ! -z "$WHEN_KILL" ]; then
    378                                 echo "Please wait $WHEN_KILL seconds."
    379                                 sleep $WHEN_KILL
    380                             fi
    381                         fi
    382                         chk_status $idx
    383                         if [ $? -eq 1 ]; then
    384                             echo_n "Kill..."
    385                             kill $pid_str >/dev/null 2>&1
    386                             if [ ! -z "$WHEN_FORCE_KILL" ]; then
    387                                 echo "Please wait $WHEN_FORCE_KILL seconds."
    388                                 sleep $WHEN_FORCE_KILL
    389                             fi
    390                         fi
    391                         chk_status $idx
    392                         if [ $? -ne 0 ]; then
    393                             echo_n "Force kill..."
    394                             kill -9 $pid_str >/dev/null 2>&1
    395                             sleep 1
    396                         fi
    397                         chk_status $idx
    398                         if [ $? -eq 0 ]; then
    399                             echo_n "Starting..."
    400                             cmd="$phd/bin/startup.sh"
    401                         else
    402                             echo_e "Unable to end process."
    403                         fi
    404                     elif [ "$opt1" = "-d" ]; then
    405                         if $diagnose_header; then
    406                             printf "%4s	%5s	%11s	%${PHD_COL_W}s
    " "ID" "PID" "State" "Program Home Directory"
    407                             diagnose_header=false
    408                         fi
    409                         local d_pid=
    410                         for d_pid in $pid_str; do
    411                             printf "%4s	%5s	%11s	%-${PHD_COL_W}s
    " "$id" "$d_pid" "$STATE_LABEL" "$phd"
    412                         done
    413                     elif [ "$opt1" = "-k" ]; then
    414                         echo_n "Kill ($id) '$phd'."
    415                         cmd="kill $pid_str"
    416                     elif [ "$opt1" = "-fk" ]; then
    417                         echo_n "Force kill ($id) '$phd'."
    418                         cmd="kill -9 $pid_str"
    419                     fi
    420                     if [ ! -z "$cmd" ]; then
    421                         `$cmd >/dev/null 2>&1`
    422                     fi
    423                     if [ -z "$executed_idxs" ]; then
    424                         executed_idxs=$idx
    425                     else
    426                         executed_idxs="$executed_idxs $idx"
    427                     fi
    428                 fi
    429             fi
    430         done
    431         if [ ! -z "$executed_idxs" ]; then
    432             if `is_contains "$opt1" "-r -h -k -fk -R"`; then
    433                 if [ ! -z "$WHEN_REVIEW" ]; then
    434                     echo "Please wait $WHEN_REVIEW seconds."
    435                     sleep $WHEN_REVIEW
    436                 fi
    437                 print_header
    438                 local idx=
    439                 for idx in $executed_idxs; do
    440                     chk_status $idx
    441                     printf "%4s	%11s	%-${PHD_COL_W}s
    " "$(expr $idx + 1)" "$STATE_LABEL" "${phd_arr[$idx]}"
    442                 done
    443                 echo_n "The command completed successfully."
    444             fi
    445         else
    446             echo_e Nothing to do.
    447         fi
    448     fi
    449 }
    450 
    451 main(){
    452     # Show usage
    453     if [ -z "$1" ]; then
    454         show_usage
    455         exit
    456     fi
    457 
    458     # Read configuration file
    459     local line=
    460     while read line; do
    461         eval "$line"
    462     done < ${0%%.*}.ini
    463 
    464     # Filling phd_arr
    465     local phd=
    466     for phd in `echo -e "${PRG_HOME_DIRS//:/\n}" | sort -u`; do
    467         phd=`to_canonical_path "$phd"`
    468         if [ ! -z "$phd" ]&&[ -x "$phd/bin/startup.sh" ]&&[ -x "$phd/bin/shutdown.sh" ]&&[ -d "$phd/webapps" ]&&[ -d "$phd/work" ]&&[ -d "$phd/logs" ]; then
    469             phd_arr[${#phd_arr[*]}]="$phd"
    470         fi
    471     done
    472 
    473     local tmp_str="${phd_arr[*]}"
    474     tmp_str=`echo -e "${tmp_str// /\n}" | sort -u`
    475     phd_arr=($tmp_str)
    476     phd_str="${phd_arr[*]}"
    477     phd_len=${#phd_arr[*]}
    478 
    479     # Check the quantity
    480     local max_phds=99
    481     if [ $phd_len -gt $max_phds ]; then
    482         echo_e "Error: 'PRG_HOME_DIRS' exceeds $max_phds."
    483         exit
    484     fi
    485 
    486     # Initialize the maximum width of the column
    487     chk_widest "$phd_str"
    488     PHD_COL_W=$WIDEST
    489 
    490     # Parameter matching
    491     if [ "$1" == "-g" ]; then
    492         echo -e "PRG_HOME_DIRS=${phd_str// /:}"
    493     elif [ "$1" == "-l" ]; then
    494         if [ $phd_len -gt 0 ]; then
    495             printf "%4s	%${PHD_COL_W}s
    " "ID" "Program Home Directory"
    496             local i=
    497             for((i=0;i<$phd_len;i++)); do
    498                 printf "%4d	%-${PHD_COL_W}s
    " "$(expr $i + 1)" "${phd_arr[$i]}"
    499             done
    500         else
    501             echo_e No data.
    502         fi
    503     elif [ "$1" == "-v" ]; then
    504         local log=${0%%.*}.log
    505         if [ -f "$log" ]; then
    506             which vi >/dev/null 2>&1
    507             if [ $? != 0 ]; then
    508                 more "$log"
    509             else
    510                 vi -M "$log"
    511             fi
    512         else
    513             echo_e No data.
    514         fi
    515     elif [ "$1" == "-s" ]; then
    516         show_status $2
    517     elif `is_contains "$1" "-d -r -h -k -fk -m -c -R"`; then
    518         exec_prg "$@"
    519     elif [ "$1" = "-D" ]; then
    520         local id=`to_positive_integer "$2"`
    521         if [ ! -z "$id" ]&&[ $id -le $phd_len ]; then
    522             local idx=$(expr $id - 1)
    523             local tmp_str=
    524             local phd=${phd_arr[$idx]}
    525             while [ $# -gt 2 ]; do
    526                 echo "Checking WAR file. '$3'"
    527                 local war_file=`trim "$3"`
    528                 local is_ok=false
    529                 if [ -z "$war_file" ]; then
    530                     echo "Cause: Empty string."
    531                 elif [[ "$war_file" == *" "* ]]; then
    532                     echo "Cause: Path contains spaces."
    533                 elif [ ! -f "$war_file" ]; then
    534                     echo "Cause: No such file."
    535                 else
    536                     local suffix="${war_file##*.}"
    537                     if [ "$suffix" != "war" ]; then
    538                         echo "Cause: File suffix is not '.war'."
    539                     else
    540                         local name=`basename "$war_file" .war`
    541                         if [ "$name" = "$war_file" ]; then
    542                             echo "Cause: Named 'war/.war'."
    543                         elif `is_contains "$war_file" "..war ...war"`; then
    544                             echo "Cause: Named '..war/...war'."
    545                         else
    546                             local filepath=`to_canonical_path "$war_file"`
    547                             unzip -t "$filepath" >/dev/null 2>&1
    548                             if [ $? != 0 ]; then
    549                                 echo "Cause: Invalid WAR file."
    550                             else
    551                                 is_ok=true
    552                                 if [ -z "$tmp_str" ]; then
    553                                     tmp_str="$filepath"
    554                                 else
    555                                     tmp_str="$tmp_str $filepath"
    556                                 fi
    557                             fi
    558                         fi
    559                     fi
    560                 fi
    561                 if $is_ok; then
    562                     echo_n Passed.
    563                 else
    564                     echo_e Failed.
    565                 fi
    566                 shift
    567             done
    568             if [ ! -z "$tmp_str" ]; then
    569                 local deployed=false dp_count=0
    570                 echo_n "Deploying ($id) '$phd'."
    571                 chk_status $idx
    572                 if [ $? -eq 1 ]; then
    573                     echo_n "Shutting down..."
    574                     "$phd/bin/shutdown.sh" >/dev/null 2>&1
    575                     if [ ! -z "$WHEN_KILL" ]; then
    576                         echo "Please wait $WHEN_KILL seconds."
    577                         sleep $WHEN_KILL
    578                     fi
    579                 fi
    580                 chk_status $idx
    581                 if [ $? -eq 1 ]; then
    582                     echo_n "Kill..."
    583                     kill $pid_str >/dev/null 2>&1
    584                     if [ ! -z "$WHEN_FORCE_KILL" ]; then
    585                         echo "Please wait $WHEN_FORCE_KILL seconds."
    586                         sleep $WHEN_FORCE_KILL
    587                     fi
    588                 fi
    589                 chk_status $idx
    590                 if [ $? -ne 0 ]; then
    591                     echo_n "Force kill..."
    592                     kill -9 $pid_str >/dev/null 2>&1
    593                     sleep 1
    594                 fi
    595                 chk_status $idx
    596                 if [ $? -eq 0 ]; then
    597                     local wfp=
    598                     stopwatch start "Deploy"
    599                     for wfp in `echo -e "${tmp_str// /\n}" | sort -u`; do
    600                         local prj_name=`basename "$wfp" .war`
    601                         stopwatch lap "Deal with '$prj_name'."
    602                         echo_n "Removing file..."
    603                         rm -rfv "$phd/webapps/$prj_name"
    604                         stopwatch lap "Remove file."
    605                         # cp: ... are the same file
    606                         echo_n "Copying file..."
    607                         cp -v "$wfp" "$phd/webapps"
    608                         stopwatch lap "Copy file."
    609                         let "dp_count+=1"
    610                     done
    611                     if [ $dp_count != 0 ]; then
    612                         echo_n "Starting..."
    613                         "$phd/bin/startup.sh" >/dev/null 2>&1
    614                         stopwatch lap "Starting '$phd'."
    615                         deployed=true
    616                     fi
    617                     stopwatch stop "completed"
    618                     stopwatch reset
    619                     stopwatch > ${0%%.*}.log
    620                 else
    621                     echo_e "Unable to end process."
    622                 fi
    623                 if $deployed; then
    624                     echo Deployed projects: $dp_count
    625                     if [ ! -z "$WHEN_REVIEW" ]; then
    626                         echo "Please wait $WHEN_REVIEW seconds."
    627                         sleep $WHEN_REVIEW
    628                     fi
    629                     print_header
    630                     chk_status $idx
    631                     printf "%4s	%11s	%-${PHD_COL_W}s
    " "$(expr $idx + 1)" "$STATE_LABEL" "${phd_arr[$idx]}"
    632                     echo_n "Project deployment has been completed."
    633                 else
    634                     echo_e "Project deployment is not completed."
    635                 fi
    636             else
    637                 echo_e No files available.
    638             fi
    639         else
    640             local result="`show_status`"
    641             echo "$result"
    642             if [ `echo "$result" | wc -l` -gt 1 ]; then
    643                 echo -e "Examples:
    	${0##*/} $1 1 mywebapp1.war mywebapp2.war..."
    644             fi
    645         fi
    646     else
    647         show_usage
    648     fi
    649 }
    650 
    651 phd_arr=() phd_str= phd_len=0
    652 pid_arr=() pid_str= pid_len=0
    653 main "$@"
    654 unset phd_arr phd_str phd_len
    655 unset pid_arr pid_str pid_len
    656 #declare
    657 
    658 :<<EOF
    659 TODO: 
    660 is_positive_number()
    661 is_positive_integer()
    662 is_negative_integer()
    663 is_negative_number()
    664 is_numeric()
    665 is_integer()
    666 # greater than 0
    667 is_gt0()
    668 to_numeric()
    669 to_integer()
    670 EOF

    附件1

    附件2

  • 相关阅读:
    .NET WinForm 状态栏添加分隔符
    使用 MMC / IE 查看证书
    配置IIS在64位Windows上运行 32 位 ASP.NET 应用程序
    WCF部署到IIS:证书必须具有能够进行密钥交换的私钥,该进程必须具有访问私钥的权限
    PB6 调用 .net Web Service
    .NET程序加壳 — 之动态加载程序集
    statusStrip 状态条 toolStripStatusLabel 居右显示
    C# 使用 Stopwatch 测量代码运行时间
    Application_Start 事件中使用 Response.Redirect
    解决IIS中部署WCF时,访问.svc文件的404错误问题
  • 原文地址:https://www.cnblogs.com/rms365/p/11231335.html
Copyright © 2020-2023  润新知