You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/bin/bash#Tomcat's catalina.sh require this lineexport JAVA_OPTS=$JAVA_OPTIONSif [[ -z"$JAVA_HOME" ]];thenecho"JAVA_HOME is not set please ensure to set this variable before calling your command"exit 1
fiif [[ -z"$TOMCAT_HOME" ]];thenecho"TOMCAT_HOME is not set please ensure to set this variable before calling your command"exit 1
fiif [[ -z"$CATALINA_BASE" ]];thenecho"CATALINA_BASE is not set please ensure to set this variable before calling your command"exit 1
fiif [[ -z"$APP_KEY" ]];thenecho"APP_KEY is not set please ensure to set this variable before calling your command"exit 1
fiif [[ -z"$JAVA_OPTS" ]];thenecho"JAVA_OPTS is not set please ensure to set this variable before calling your command"exit 1
fiprompt_confirm() {
whiletrue;doread -r -n 1 -p "${1:-Continue?} [y/n]: " REPLY
case$REPLYin
[yY]) echo;return 1 ;;
[nN]) echo;return 0 ;;
*) printf" \033[31m %s \n\033[0m""invalid input"esacdone
}
############################################################################ Purpose : Function to execute the command passed using command line# Argument: Command to be executed###########################################################################functionexecute_command {
case"$1"in
(start)
echo"Starting Tomcat using $TOMCAT_HOME/bin/startup.sh"$TOMCAT_HOME/bin/startup.sh
;;
###########################################################################
(restart)
echo"Killing Current Running Process (if any)."
ps -eaf | grep -v grep | grep $APP_KEY| awk '{print $2}'| xargs killecho"Starting Tomcat using $TOMCAT_HOME/bin/startup.sh"$TOMCAT_HOME/bin/startup.sh
;;
###########################################################################
(stop)
echo"Stoping Tomcat using $TOMCAT_HOME/bin/shutdown.sh"$TOMCAT_HOME/bin/shutdown.sh
;;
###########################################################################
(kill)
# echo "Killing Tomcat using ps -ef | grep $APP_KEY | grep -v grep | awk '{print $2}' | xargs kill"
prompt_confirm "Did you try stop?"|| ps -eaf | grep -v grep | grep $APP_KEY| awk '{print $2}'| xargs kill
;;
###########################################################################
(kill9)
# echo "Killing Tomcat using ps -ef | grep $APP_KEY | grep -v grep | awk '{print $2}' | xargs kill -9"
prompt_confirm "Did you try stop?"|| ps -eaf | grep -v grep | grep $APP_KEY| awk '{print $2}'| xargs kill -9
;;
###########################################################################
(tail)
echo"$CATALINA_BASE/logs/catalina.out"
tail -f $CATALINA_BASE/logs/catalina.out
;;
###########################################################################
(tail_all)
echo"$CATALINA_BASE/logs/*"
tail -f $CATALINA_BASE/logs/*
;;
###########################################################################
(home_tail)
echo"$CATALINA_HOME/logs/catalina.out"
tail -f $CATALINA_HOME/logs/catalina.out
;;
###########################################################################
(home_tail_all)
echo"$CATALINA_HOME/logs/*"
tail -f $CATALINA_HOME/logs/*
;;
###########################################################################
(home_clean)
echo"Delete all file inside $CATALINA_HOME/logs/*"
prompt_confirm "Delete Logs?"|| rm -rf $CATALINA_HOME/logs
if [[ !-d"$CATALINA_HOME/logs" ]];then
mkdir $CATALINA_HOME/logs
fi
;;
###########################################################################
(clean)
echo"Delete all file inside $CATALINA_BASE/logs/*"
prompt_confirm "Delete Logs?"|| rm -rf $CATALINA_BASE/logs
if [[ !-d"$CATALINA_BASE/logs" ]];then
mkdir $CATALINA_BASE/logs
fi
;;
###########################################################################
(status)
#echo "Running Tomcat process..."
OUTPUT="$(ps -eaf | grep -v grep | grep $APP_KEY)"
COUNT="$(echo \"${OUTPUT}\"| wc -w)"# echo "${OUTPUT}"# echo "COUNT === ${COUNT}"if [ "$COUNT"-gt"1" ];thenecho"${OUTPUT}"elseecho"${APP_KEY} is not running..."fi
;;
###########################################################################
(*)
# echo "Running Tomcat process..."# ps -eaf | grep -v grep | grep $APP_KEYecho"Usage: $0 [start|stop|status|kill|kill9|restart|tail|tail_all|clean|home_clean]"exit 1
esac
}
# echo "JAVA_OPTS = $JAVA_OPTS"
execute_command $1#If user wants to tail post command execution we pass the second argument for parsing.if [[ $2==*"tail_all"* ]]
then
execute_command $2fi#If user wants to tail post command execution we pass the second argument for parsing.if [[ $2==*"tail"* ]]
then
execute_command $2fi
domain.sh
#!/bin/bash
JAVA_HOME=/usr/local/jdk1.8
TOMCAT_HOME=/usr/local/apache-tomcat-8.0.28
export CATALINA_BASE=/usr/local/tomcat_domains/domain
# Identify this process for monitoring.
APP_KEY="tomcat-domain-`hostname -s`"
JAVA_OPTIONS="-Djava.endorsed.dirs=$CATALINA_BASE/endorsed \-Dcatalina.base=$CATALINA_BASE\-Dcatalina.home=$TOMCAT_HOME\-Djava.io.tmpdir=$CATALINA_BASE/tmp \-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties \-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager-Dapp.key=$APP_KEY"#Tomcat's catalina.sh require this lineexport JAVA_OPTS=$JAVA_OPTIONS#Call the common Stuff
CURRENTDIR=`dirname $0`.$CURRENTDIR/../tomcat_common.sh