Linux restarts the Tomcat service on a regular basis

Source: Internet
Author: User

1: Check the status of the Crond service (confirm that the Linux Task Scheduler service is turned on)

Service Crond Status

Crond (PID 1937) is running ...

2: Write the SH executable file that restarts Tomcat restart_tomcat.sh

#!/bin/sh

#./etc/profile

Export java_home=/usr/java/jdk1.8.0_112

sh/opt/apache-tomcat-9.0.0.m11/bin/shutdown.sh

Sleep 60s

sh/opt/apache-tomcat-9.0.0.m11/bin/startup.sh

3: Manually test whether the file can be executed

[Email protected] bin]#./restart_tomcat.sh

-bash:./restart_tomcat.sh:/bin/sh^m:bad interpreter:no such file or directory

The above error is because restart_tomcat.sh is created directly under the window system and needs to be modified in the format of the file.

For the Linux system format, execute the following command in turn:

---------------------------------------------------------------------------------------------------------

Assigning Permissions to Files

chmod 777 restart_tomcat.sh

then modify the file format  
VI restart_tomcat.sh
use the following command to view the file format  
: Set FF or: Set FileFormat
You can see the following information
Fileformat=dos or Fileformat=unix
use the following command to modify the file format  
: Set Ff=unix or: Set Fileformat=unix
Save exit
: Wq

After performing the above operation, perform the discovery execution OK again

[Email protected] bin]#./restart_tomcat.sh

Using catalina_base:/opt/apache-tomcat-9.0.0.m11

Using Catalina_home:/opt/apache-tomcat-9.0.0.m11

Using Catalina_tmpdir:/opt/apache-tomcat-9.0.0.m11/temp

Using Jre_home:/usr/java/jdk1.8.0_112

Using CLASSPATH:/opt/apache-tomcat-9.0.0.m11/bin/bootstrap.jar:/opt/apache-tomcat-9.0.0.m11/bin/tomcat-juli.jar

Using catalina_base:/opt/apache-tomcat-9.0.0.m11

Using Catalina_home:/opt/apache-tomcat-9.0.0.m11

Using catalina_tmpdir:/opt/apache-tomcat-9.0.0.m11/temp

Using Jre_home:/usr/java/jdk1.8.0_112

Using CLASSPATH:/opt/apache-tomcat-9.0.0.m11/bin/bootstrap.jar:/opt/apache-tomcat-9.0.0.m11/bin/tomcat-juli.jar

Tomcat started.

4: Add crontab Task Scheduler

[Email protected] bin]# CRONTAB-E

0 1 * * */opt/apache-tomcat-9.0.0.m11/bin/restart_tomcat.sh

Execute the restart_tomcat.sh file under the specified path every 1 o'clock in the morning

Linux restarts the Tomcat service on a regular basis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.