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 ());