To determine whether the service registered by wrapper services is started

Source: Internet
Author: User
Tags socket wrapper

In my previous article, I introduced the use of the Apache Wrapper service tool to register Java programs as operating systems, if you use the "Implementation Wrapperlistener this interface and combine wrapper.conf" this way to start the service, and setting the Wrapper.ignore_signals property to the API provided by the True,wrapper service in the wrapper.conf configuration file does not correctly determine whether the service is starting properly, because wrapper.ignore_ The signals property is used to mask the message mechanism of the operating system, such as pressing CTRL + C at the command Line window that initiates the service, or shutting down the command Line window on which the service is started, so that the service does not stop, which prevents misoperation.

In fact, wrapper service This tool is to communicate through the socket and the JVM (by the way, so that the service can be started normally can be affected by the local firewall, I have encountered this situation), in wrapper The service's profile allows you to specify the ports that the services use (the default is a random selection of ports, which is unreliable), so that the Java socket can be used to determine whether the service can be started properly.

For example, the port used by our service is 3976, the Java code to judge is:

/**
    * 检查服务器连接状态。
    * @author vwpolo
    * @return String
    */
   private String getWrapperServiceState() {
     try {
       InetSocketAddress socketAddress = new InetSocketAddress("127.0.0.1",3976);
       Socket socket = new Socket();
       socket.connect(socketAddress,60000);
       return "已启动";
     }catch (Exception e) {
       return "已经停止";
     }
   }

Test code:

SYSTEM.OUT.PRINTLN ("Service startup status:" + getwrapperservicestate ());

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.