#!/bin/sh
####################################################################
# Created by: Abhijit Sandhan
# Purpose: Start/Stop/Restart Apache Tomcat service
####################################################################
# Check the path of Tomcat and set environment variables as follows
# in the .bashrc profile
export CATALINA_HOME="/usr/local/tomcat7/apache-tomcat-7.0.37"
export CATALINA_BASE="/usr/local/tomcat7/apache-tomcat-7.0.37"
export JAVA_HOME="/usr/local/java/jdk1.7.0_17"
export JAVA_HOME=/usr/local/java/jdk1.7.0_17
#Use Case statement to start / stop /reset tomcat service
case $1 in
start)
cd /usr/local/tomcat7/apache-tomcat-7.0.37/bin/
./startup.sh
;;
stop)
cd /usr/local/tomcat7/apache-tomcat-7.0.37bin/
./shutdown.sh
;;
restart)
cd /usr/local/tomcat7/apache-tomcat-7.0.37/bin/
./shutdown.sh
cd /usr/local/tomcat7/apache-tomcat-7.0.37/bin/
./startup.sh
;;
esac
exit 0
Note: Make sure to replace the tomcat, java directory paths & variables according to your server settings in the above script.
Step 2. Copy the tomcat script under /etc/init.d directory
cp tomcat /etc/init.d/
Step 3. Create symlinks to start/stop/restart tomcat service for desired Runlevel
Example: For Runlevel 2
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
Step 4. Reboot server to verify if following commands are working or not
To start:
/etc/init.d/tomcat start
To stop:
/etc/int.d/tomcat stop
To restart:
/etc/init.d/tomcat restart
Step 5. Now enable Apache Tomcat service to start on every server boot
For RHEL / CentOS 6.x & Ubuntu
chkconfig tomcat on
To confirm if the service is added successfully:
chkconfig --list tomcat on
For RHEL / CentOS 7.x
systemctl enable tomcat
To confirm if the service is added successfully:
systemctl status tomcat
Hope this helps!
Không có nhận xét nào:
Đăng nhận xét