#!/usr/bin/ksh ################################################################################ #The script is called by java. #The script just can output 0 or 1, please don't echo other information out. #If you do so, the script will be failed in testing the result of it. ################################################################################ check_tomcat_proc_exist() { sso_user=`whoami` sso_pro=`ps -fu ${sso_user} | grep ${process_name} |grep -v 'grep' | awk '{print $2}'` if [ "X${sso_pro}" = "X" ];then echo 1 return 1 else echo 0 fi return 0 } stop_tomcat() { check_tomcat_proc_exist 1>/dev/null 2>&1 if [ $? -ne 0 ];then echo 1 return 0 fi cd ${tomcat_home}/bin shutdown.sh 1>/dev/null 2>&1 if [ $? -ne 0 ]; then echo 1 fi echo 0 return 0 } kill_tomcat() { sso_user=`whoami` sso_pro=`ps -fu ${sso_user} | grep ${process_name} |grep -v 'grep' | awk '{print $2}'` if [ "X${sso_pro}" = "X" ];then echo 1 else kill -9 $sso_pro echo 0 fi return 0 } start_tomcat() { check_tomcat_proc_exist 1>/dev/null 2>&1 if [ $? -eq 0 ];then echo 1 return 0 fi if [ -f ${tomcat_home}/logs/catalina.out ];then mv -f ${tomcat_home}/logs/catalina.out ${tomcat_home}/logs/catalina.out.old fi if [ -f ${tomcat_home}/bin/logs/ssoserver.log ];then mv -f ${tomcat_home}/bin/logs/ssoserver.log ${tomcat_home}/bin/logs/ssoserver.log.old fi cd ${tomcat_home}/bin nohup startup.sh >/dev/null 2>&1 & if [ $? -ne 0 ]; then echo 1 return 1 fi typeset idx=0 typeset expire_times=180 while [ ${idx} -lt ${expire_times} ] do grep -i "Server startup" "${tomcat_home}/logs/catalina.out" 1>/dev/null 2>&1 if [ $? -eq 0 ];then grep -i "ERROR" "${tomcat_home}/bin/logs/ssoserver.log" 1>/dev/null 2>&1 if [ $? -ne 0 ];then echo 0 else kill_tomcat >/dev/null 2>&1 & fi return 0 fi ((idx=idx+1)) sleep 1 done } typeset process_name="org.apache.catalina" typeset tomcat_home=$HOME/tomcat if [ "X$1" = "Xproc" ]; then check_tomcat_proc_exist elif [ "X$1" = "Xstart" ]; then start_tomcat elif [ "X$1" = "Xstop" ]; then stop_tomcat elif [ "X$1" = "Xkill" ]; then kill_tomcat else echo "please input parameter." fi