Bash Shell Script for Apache Tomcat Start and Stop

Here is the bash script in Linux for Start, Stop & Restart of Apache Tomcat server.

shell script

Please follow the article for Installation of Apache Tomcat in Linux and If Java is not Installed,



Kindly Install Java in Linux using this article –
How to Install Java JDK in Linux

 

Copy and Paste the below shell script using Vi text editor.

#!/bin/bash
# description: Script to Start Stop Restart Tomcat
JAVA_HOME=/usr/java/default
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
TOMCAT_HOME=/opt/tomcat-8/bin
JAVA_OPTS="-Xms2048m -Xmx8192m -XX:MaxPermSize=512m
export JAVA_OPTS
case $1 in
start)
/bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/startup.sh
;;
stop)

/bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/shutdown.sh
;;
restart)
/bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/shutdown.sh
/bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/startup.sh
;;
esac
exit 0

we need to set the JAVA_HOME & TOMCAT_HOME path according to our configurations. For example, in the above script, JAVA_HOME is /usr/java/default And TOMCAT_HOME is /opt/tomcat-8/bin

Save the tomcat-8.sh file in the /etc/init.d/ directory

# cp tomcat-8.sh /etc/init.d/
# chmod +x tomcat-8.sh

Now to start the script,

# ./tomcat-8.sh start

For stop,

# ./tomcat-8.sh stop

To restart

># ./tomcat-8.sh restart

We have seen about the Shell script for tomcat start & stop in Linux.[adAuto]

Do you know How to 

[adHoriL]
Kindly share your thoughts & comments in the below form,

YOU MAY ALSO LIKE....

Leave a Reply

Be the First to Comment!

avatar
166
wpDiscuz