Register Tomcat as a Windows service)

Source: Internet
Author: User
Recently, I don't know what's going on. The program on the server suddenly goes wrong. Some pages cannot be accessed normally, or only half of them are displayed. I have encountered this problem before, it should be because a problem occurs when reading data, and it is said that such a release still has some potential risks.
At the beginning, for the convenience of users, I directly registered Tomcat as a Windows service and set the Startup Type to "auto start", so that even if the user restarts the Server due to power failure or other reasons, the program can also start automatically without manual start. It was not until today that this problem was exposed that I realized a big problem: when the program starts, it needs to connect to the database, but the database service often starts slowly. Therefore, before the database service is fully started, if the application service has been started, an error may occur.
Google has spent half a day using the following solutions:

Java code
  1. SC config tomcatapp depend = oracleserviceopb/oracleserviceorcl
sc config tomcatAPP depend= OracleServiceOPB/OracleServiceORCL

That is to say, the Tomcat service is set to depend on the two database services. That is, Tomcat is started only after the two database instances are started.
Note that the service name "atatapp" is not displayed in the service list. The name is not accurate:


Here, we need to write "service name" instead of "display name". Or, the simplest is to go to the Registry HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services to see the real service name. In addition, the SC command format should also be noted that "depend =" is an overall command parameter, followed by a space, and then followed by the dependent service name, multiple services are separated by commas (,). The service name is not enclosed in quotation marks.
After this command is completed, we can see that the dependency between the Tomcat service and the Oracle service is indeed established:


However, the problem persists after the restart !! Google again. Wait until the problem is solved ~~

To sum up all the steps, we hope that the experts will give you some advice:
1. Open cmd.
2. Go to the tomcat_home/bin directory.
3. Enter the command "service install tomcatapp" to install the service. The command to uninstall the service is: "service reomve tomcatapp"
. 4. Set the service to auto start and enter the command "SC config tomcatapp start = auto ".
5. Set the service dependency and enter the command: "SC config tomcatapp depend = oracleserviceopb/oracleserviceorcl"
6. Restart the machine to see if it works.

Related Article

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.