vi /etc/init.d/tomcat
#!/bin/sh
#
# /etc/init.d/tomcat
# chkconfig: 234 20 80
# This is the init script for starting up the
# Jakarta Tomcat server
#
# description: Starts and stops the Tomcat daemon.
#
tomcat=/opt/apache-tomcat-6.0.18
startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh
start() {
echo -n $"Starting Tomcat service: "
sh $startup
echo $?
}
stop() {
echo -n $"Stopping Tomcat service: "
sh $shutdown
echo $?
}
restart() {
stop
start
}
status() {
ps -aef | grep apache-tomcat | grep -v tomcat6 | grep -v grep
}
# Handle the different input options
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
Note that when you run a process as a service, its environment may be different from the environment you see when you log in.
- Under SUSE Linux, you may wish to add the line below to the top of the tomcat script to ensure that the tomcat process will run with the environmental variables that you have set in “/etc/profile”.source /etc/profile
- To see what environment a process is running under, you can use the following commands:ps -aef | grep tomcat
... you will get a process id number like 5054 ...
cat /proc/5054/environ
cd /etc/init.d
chmod u+x tomcat
cd /etc/init.d
./tomcat status
service tomcat start
service tomcat stop
service tomcat restart
service tomcat status
chkconfig tomcat on