In the Linux system, configure tomcat as a system service:
(1) Copy the catalina.sh file in the tomcat and bin directory to the /etc/init.d directory and rename it to tomcat_task (service name)
(2) Modify the script
Add the following two lines of comment to the position earlier in the script :
#chkconfig:2345 10 90
#description:Tomcat service
If this step is not done, the following error will appear: tomcat does not support chkconfig
(3) Set environment variables in the script
CATALINA_HOME=/usr/java/tomcat
JAVA_HOME=/usr/java/jdk8
Some people may have doubts, why do you need to set CATALINA_HOME and JAVA_HOME that have already been set in the system variables. This is related to the service command of the linux system. When the service runs the specified service (called the System V initial script), most of the environment variables are removed, only the two environment variables of LANG and TERM are retained, and the current path is set to /, That is to run the service script in a predictably very clean environment. This script is stored in the /etc/init.d directory, and it supports at least the start and stop commands.
So, to reset the environment variables.
(4) Modify the executable permission of the script
chmod 755 /etc/init.d/tomcat_task
(5) Add as a system service
chkconfig --add tomcat_task
After the addition is complete, check whether there is a service called tomcat_task in the system service list. If yes, it means the addition was successful
(6) Start tomcat
service tomcat_task start
(7) Close tomcat
service tomcat_task stop
Supplementary note: After the above steps are completed, it is found that the tomcat service is started, but if there are other custom environment variables in the project, you need to add a line of source /etc/profile to load the custom system parameters.