Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to write the startup service script of CentOS Tomcat

Shulou Source: shulou.com Published: 2022-06-01 07:15:20 10月03日 Update

CentOS Tomcat startup service script how to write, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

1. Tomcat comes with jsvc. This tool starts 2 threads. If the application monopolizes the resources, it will cause the application to fail to start. This is the same as the daemon project in Apache Commons.

2. Java Service Wrapper

Referring to the script of nginx, I wrote a script for your reference:

The code is as follows:

#

#! / bin/bash

#

# chkconfig:-91 35

# description: Starts and stops tomcat

CATALINA_HOME=/data/site/tomcat-8085

PID_FILE=/var/run/tomcat8085.pid

JAVA_HOME=/usr/java/default

JAVA_OPTS= "- server-Xms512m-Xmx1024m"

CATALINA_BASE=$CATALINA_HOME

CATALINA_OPTS= "- Djava.library.path=$CATALINA_HOME/bin"

CLASSPATH=\

$JAVA_HOME/lib/tools.jar:\

$CATALINA_HOME/bin/commons-daemon.jar:\

$CATALINA_HOME/bin/bootstrap.jar

RETVAL=0

# Source function library.

. / etc/rc.d/init.d/functions

# Source networking configuration.

. / etc/sysconfig/network

# Check that networking is up.

[${NETWORKING} = "no"] & & exit 0

# Start daemons functions.

Start () {

#

# Start Tomcat

#

If [- e $PID_FILE]; then

Echo "$PID_FILE already running...."

Exit 1

Fi

Echo-n $"Starting $PID_FILE:"

Nohup $JAVA_HOME/bin/java\

-Dcatalina.home=$CATALINA_HOME\

-Dcatalina.base=$CATALINA_BASE\

-Djava.io.tmpdir=$TMP_DIR\

$CATALINA_OPTS\

-cp $CLASSPATH\

$JAVA_OPTS\

Org.apache.catalina.startup.Bootstrap start > $CATALINA_HOME/logs/catalina.out &

RETVAL=$?

Echo

[$RETVAL = 0] & & touch $PID_FILE

Return $RETVAL

}

# Stop daemons functions.

Stop () {

#

# Stop Tomcat

#

Echo-n $"Stopping $PID_FILE:"

Nohup $JAVA_HOME/bin/java\

-Dcatalina.home=$CATALINA_HOME\

-Dcatalina.base=$CATALINA_BASE\

-Djava.io.tmpdir=$TMP_DIR\

$CATALINA_OPTS\

-cp $CLASSPATH\

Org.apache.catalina.startup.Bootstrap stop > $CATALINA_HOME/logs/catalina.out &

RETVAL=$?

Echo

[$RETVAL = 0] & & rm-f $PID_FILE

Return $RETVAL

}

# See how we were called.

Case "$1" in

Start)

Start

Stop)

Stop

Restart)

Stop

Start

*)

Echo $"Usage: $prog {start | stop | restart}"

Exit 1

Esac

Exit $RETVAL

Installation steps

1. # vi tomcatd enter the above script

2. # chmod + x tomcatd is configured with execution permission

3. # copy cp tomcatd / etc/init.d to the startup directory

4. # chkconfig-add tomcatd

5. # chkconfig tomcatd on

6. # service tomcatd start start

7. # service tomcatd stop stop

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Scripts references help applications services clarity code content for this tools articles novices more permissions steps directories knowledge threads industries resources Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Redmi Shulou Technology NVidia MariaDB