CentOS Tomcat的启动服务脚本怎么写

2023-04-14 02:54:00 服务 启动 脚本

CentOS Tomcat的启动服务脚本怎么写

在CentOS上安装好Tomcat后,要想让Tomcat作为服务来启动,需要编写一个启动脚本。下面介绍一下如何编写Tomcat的启动脚本。

首先,在Tomcat的安装目录下新建一个名为“tomcat”的文件夹,然后将Tomcat的“bin”目录下的所有文件复制到“tomcat”文件夹中。

然后,在“tomcat”文件夹中新建一个名为“tomcat.sh”的文件,文件内容如下:

#!/bin/sh # chkconfig: 2345 20 80 # description: Tomcat # processname: tomcat # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 tomcat="/usr/local/tomcat" lockfile=/var/lock/subsys/tomcat # Get config. . $tomcat/conf/tomcat.conf # Set defaults. if [ -z "$JAVA_HOME" ]; then JAVA_HOME=/usr/java/latest fi # See how we were called. case "$1" in start) echo -n $"Starting $prog: " # Start daemons. # Start Tomcat touch $lockfile $tomcat/bin/startup.sh RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/run/tomcat.pid ;; stop) echo -n $"Stopping $prog: " # Stop daemons. $tomcat/bin/shutdown.sh RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat /var/run/tomcat.pid ;; restart) $0 stop $0 start ;; status) status tomcat ;; *) echo $"Usage: $0 {start|stop|restart|status}" exit 1 esac exit $?

相关文章