Preface:
The following bash script file can be used on Linux instances to startup a Tomcat server as a service. The script does need some minor modifications to suit your specific instance of Linux. The following two variables must be changed:
1. The JAVA_HOME variable must point to an installed version of java on your system.
2. The tomcat_home variable must pouint to an installed Tomact server on your system
Bash script sample:
- #!/bin/bash
- # This is the init script for starting up the
- # Jakarta Tomcat server
- #
- # chkconfig: 345 91 10
- # description: Starts and stops the Tomcat daemon.
- #
- # Source function library.
- . /etc/rc.d/init.d/functions
- # Get config.
- . /etc/sysconfig/network
- # Check that networking is up.
- [ "${NETWORKING}" = "no" ] && exit 0
- export JAVA_HOME=/usr/local/jdk
- tomcat_home=/usr/local/jakarta-tomcat
- startup=$tomcat/bin/startup.sh
- shutdown=$tomcat/bin/shutdown.sh
- start(){
- echo -n "Starting Tomcat service:"
- cd $tomcat_home
- $startup
- echo "done"
- }
- stop(){
- echo -n "Shutting down tomcat: "
- cd $tomcat_home
- $shutdown
- echo "done."
- }
- status(){
- numproc=`ps -ef | grep catalina | grep -v "grep catalina" | wc -l`
- if [ $numproc -gt 0 ]; then
- echo "Tomcat is running..."
- else
- echo "Tomcat is stopped..."
- fi
- }
- restart(){
- stop
- start
- }
- # See how we were called.
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- status)
- status
- ;;
- restart)
- restart
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart}"
- exit 1
- esac
Supplement:
* 鳥哥 Linux 私房菜 > 認識系統服務 (daemons)
沒有留言:
張貼留言