Embodiment
In order to improve the troubleshooting efficient to network server, the present invention provides a kind of method for supervising of network server, in this method; Setting has the running environment of two instances of specifying corresponding relation, starts network server, moves the instance of two network servers automatically; One of them instance is as monitoring program; The monitoring program of operation exception is closed and restarted to another instance when primary control program monitors the monitoring program operation exception, as primary control program; When monitoring program monitors the primary control program operation exception, close the primary control program of operation exception, self is set to primary control program, and the primary control program that restarts operation exception is as monitoring program.
Network server in the embodiment of the invention has many message interfaces, and client-side program obtains the information service that network server provides through message interface.Network server will be realized such service, and the ServerSocket with multithreading disposal ability is installed, and the PORT COM of ServerSocket is set, and announces oneself IP address and PORT COM to client.Client also must just possibly obtain the information service that network server provides after having connected this IP address and PORT COM.In addition, network server also will possess in a plurality of threads the access ability to database, realizes the information service to client through the information exchange with database.These are necessary configuration of network server and function.Simultaneously, network server also will be installed the ClientSocket control except that the ServerSocket control is installed.This is when moving two instance programs, sets up the usefulness of the channel of mutual communication.
Referring to Fig. 1, the method for supervising of the network server that the embodiment of the invention provides specifically may further comprise the steps:
Step 10: start network server, move two instances of this network server, one of them instance is set to monitoring program, and another instance is set to primary control program;
Step 11: when primary control program monitors the monitoring program operation exception, close and restart the monitoring program of operation exception;
Step 12: when monitoring program monitors the primary control program operation exception, close the primary control program of operation exception, self is set to primary control program, and the primary control program that restarts operation exception is as monitoring program.
In the step 10, before starting network server, has the running environment of two instances of specifying corresponding relation for this network server setting; For example, the filename of network server is fznet.exe.The operation catalogue of first instance is " c: network service A ", and the operation catalogue of second instance be " c: network serve B ".Such configuration guarantees the running environment of another instance that the instance of any operation all can be confirmed to match.And, just do not have the network server of mutual monitoring function to move as one when the example detection of operation during less than the running environment of this another instance with definite corresponding relation.
As shown in Figure 2, the concrete realization of step 10 comprises the steps:
Step 20: behind the instance in the running environment of two instances of startup network server; This instance obtains the running environment sign of self instance; According to the corresponding relation of the running environment sign of two instances that are provided with in advance, confirm the running environment sign of adjacent instance; The adjacent each other instance of two instances of network server.
After an instance in the running environment of two instances starts; This instance is according to the running environment sign of self; Automatically detect the running environment that is provided with in advance with another instance of specifying corresponding relation; If do not detect, then this instance is as a network server that does not have mutual monitoring function, and start-up course finishes; If detect, just obtain the running environment sign (like Bcxhj) of self instance and the running environment of adjacent instance and identify (like Xlcxhj).
Step 21: self instance is set to monitoring program, sets up the communication channel with primary control program, through this communication channel to primary control program send state information query requests;
The concrete grammar that self instance is set to monitoring program is: the running status sign of self instance is set to the running status sign of monitoring program; For self instance is provided with the main window title or the system banner of corresponding monitoring program, for self instance is created the resource that needs with the primary control program information interaction.
Step 22: judge whether self instance receives the state information of the normal operation of primary control program, if then start-up course finishes, otherwise, change step 23;
Step 23: whether have primary control program operation, if having, then close this primary control program if detecting;
Step 24: self instance is set to primary control program;
Step 25: the running environment sign according to the adjacent instance of self instance starts adjacent instance.
As shown in Figure 3, the concrete realization of step 11 may further comprise the steps:
Step 30: primary control program is set up the communication channel with monitoring program, through this communication channel to monitoring program send state information query requests;
Primary control program foundation with the concrete grammar of the communication channel of monitoring program is: the ServerSocket assembly of primary control program takies the PORT COM into client service; The PORT COM of the ServerSocket assembly of monitoring program is set to have the PORT COM of specifying corresponding relation with the PORT COM of the ServerSocket assembly of primary control program, the ClientSocket assembly of primary control program connect monitoring program the ServerSocket assembly PORT COM and carry out the function with the monitoring program information interaction.
Through the send state information query requests, primary control program can obtain the state information that this monitoring program is moved normal or operation exception from monitoring program.
Step 31: when not receiving the state information of the normal operation of monitoring program, whether have monitoring program operation, if having, to step 32 if detecting; Otherwise, to step 33;
Step 32: close this monitoring program;
Step 33: utilize the running environment sign of adjacent instance to start the adjacent instance of operation.After adjacent instance starts, repeat above-mentioned steps 20-step 25.
As shown in Figure 4, the concrete realization of step 12 may further comprise the steps:
Step 40: monitoring program is set up the communication channel with primary control program, through this communication channel to primary control program send state information query requests;
Monitoring program foundation with the concrete grammar of the communication channel of primary control program is: the ServerSocket assembly of primary control program takies the PORT COM into client service; The PORT COM of the ServerSocket assembly of monitoring program is set to have the PORT COM of specifying corresponding relation with the PORT COM of the ServerSocket assembly of primary control program, the ClientSocket assembly of monitoring program connect primary control program the ServerSocket assembly PORT COM and carry out the function with the primary control program information interaction.
Through the send state information query requests, monitoring program can obtain the state information of running status, fault message or the operation exception of this primary control program network service processes from primary control program.And can obtain state informations such as the number of threads that connects in real time, real-time database number of connection, the fault of classifying according to the requirement of various network service routine.
Step 41: when not receiving the state information of the normal operation of primary control program, whether have primary control program operation, if having, then arrive step 42 if detecting; Otherwise, to step 43;
Step 42: close this primary control program;
Step 43: monitoring program self instance is set to primary control program;
The concrete grammar that self instance is set to primary control program is: the running status sign of self instance is set to the running status sign of primary control program; The main window title or the system banner of corresponding primary control program are set for self instance; For self instance create with the monitoring program information interaction with carry out the resource that network service function needs, start network service function to client.
Step 44: utilize the running environment sign of adjacent instance to start the adjacent instance of operation.After adjacent instance starts, repeat above-mentioned steps 20-step 25, to keep the capable state of hot received shipment of primary control program and monitoring program mutual monitoring.
Whether in step 24 and the step 41, detecting has the concrete grammar of monitoring program operation to be:
Through whether there being the running status sign corresponding programs of main window title or system banner and monitoring program in application programming interfaces (API) the function detection system, if then judging has monitoring program; Otherwise, judge no monitoring program.
Whether detect in the step 31 has the concrete grammar of primary control program operation to be:
Through whether there being the running status sign corresponding programs of main window title or system banner and primary control program in the api function detection system, if then judging has primary control program; Otherwise, judge no master control program.
In the embodiment of the invention, when working in the capable state of the hot received shipment of primary control program and monitoring program mutual monitoring, any one instance is closed in manual work, all can restart an instance automatically, makes it remain on the capable state of hot received shipment.Program can't stop like this.Can be handling for what guarantee network server, the present embodiment setting is accomplished this heat and is equipped with closing of system by " system withdraws from " button at primary control program interface.Click " system withdraws from " button at primary control program interface, accomplish closing of network server through following controlled step:
At first, stop the running status inquiry of primary control program to monitoring program;
Then, obtain the handle of monitoring program, the api function that utilizes this handle call operation system to provide is closed monitoring program;
At last, close primary control program.
So just closed and be in the capable network server of hot received shipment.
In the embodiment of the invention, the port that is used to client service that the PORT COM of the ServerSocket of primary control program must be set to set in the configuration file is to guarantee the channel of primary control program to client service.Has definite corresponding relation according to the PORT COM of the ServerSocket of configuration file monitoring program and the PORT COM of primary control program ServerSocket.For example, the PORT COM of primary control program ServerSocket is AA, and the PORT COM of monitoring program ServerSocket is AA+1.After the operation of the instance of any running environment, according to the running status sign of self all can be correct the ServerSocket PORT COM that self is set.Also know the ServerSocket PORT COM of adjacent instance simultaneously according to configuration file.
Primary control program and the IP address of the server end that ClientSocket was connected of monitoring program all are made as the IP address of this machine, generally can be made as 127.0.0.1 (this machine IP).Because method of the present invention is that the network server heat of two instances on same machine is equipped with.Be set to the PORT COM of monitoring program ServerSocket according to the PORT COM of the ClientSocket of configuration file primary control program, the PORT COM of the ClientSocket of monitoring program is set to the PORT COM of primary control program ServerSocket.Constitute the communication channel that primary control program and monitoring program are monitored each other thus.
Referring to Fig. 5, the embodiment of the invention also provides a kind of watch-dog of network server, and this equipment comprises:
Operation module 50 is used to start network server, moves two instances of this network server, and one of them instance is set to monitoring module, and another instance is set to main control module;
The monitoring module of operation exception is closed and restarted to main control module 51 when being used to monitor the monitoring module operation exception;
Monitoring module 52 when being used to monitor the main control module operation exception, is closed the main control module of operation exception, and self is set to main control module, and the main control module that restarts operation exception is as monitoring module.
This equipment further comprises:
Environment is provided with module 53, is used to the running environment that said network server setting has two instances of specifying corresponding relation;
Said operation module 50 comprises:
Identification module after the instance that is used for the running environment of said two instances starts, obtains the running environment sign of this instance, according to the corresponding relation of the running environment sign of two instances that are provided with in advance, confirms the running environment sign of adjacent instance;
The status poll module, the instance that is used for starting is set to monitoring module, sets up the communication channel of monitoring module and main control module, through this communication channel to main control module send state information query requests; The method that instance is set to monitoring module is: the running status sign of instance is set to the running status sign of monitoring module; For instance is provided with the main window title or the system banner of relative detecting module, be the resource that instance is created to be needed with the main control module information interaction.
Detection module is used for when said status poll module does not receive the state information of the normal operation of main control module, and whether have main control module operation, if having, then close this main control module if detecting.Whether have the method for main control module operation be: through whether there being the running status sign corresponding programs of main window title or system banner and main control module in the api function detection system, if then judging has main control module if detecting; Otherwise, judge no master control module.
Instance is provided with module, and the instance that is used for starting is set to main control module;
Start module, be used for starting adjacent instance according to the running environment sign of said adjacent instance.
Said main control module 51 comprises:
First passage is set up module, is used to set up the communication channel with monitoring module; Concrete method for building up is: the ServerSocket assembly of main control module is taken the PORT COM into client service; The PORT COM of the ServerSocket assembly of monitoring module is set to have the PORT COM of specifying corresponding relation with the PORT COM of the ServerSocket assembly of main control module, the ClientSocket assembly of main control module connect monitoring module the ServerSocket assembly PORT COM and carry out the function with the monitoring program information interaction.
First request module is used for through said communication channel to monitoring module send state information query requests;
First closing module is used for when said first request module does not receive the state information of the normal operation of monitoring module, and whether have monitoring program operation, if having, then close this monitoring program if detecting.Whether have monitoring module operation comprise: through whether there being the running status sign corresponding programs of main window title or system banner and monitoring module in the api function detection system, if then judging has monitoring module if detecting; Otherwise, judge no monitoring module.
The first adjacent instance starts module, is used to utilize the running environment sign of said adjacent instance to start the adjacent instance of operation.
Said monitoring module 52 comprises:
Second channel is set up module, is used to set up the communication channel with main control module; Concrete method for building up is: the ServerSocket assembly of main control module is taken the PORT COM into client service; The PORT COM of the ServerSocket assembly of monitoring module is set to have the PORT COM of specifying corresponding relation with the PORT COM of the ServerSocket assembly of main control module, the ClientSocket assembly of monitoring module connect main control module the ServerSocket assembly PORT COM and carry out the function with the primary control program information interaction.
Second request module is used for through said communication channel main control module send state information query requests;
Second closing module is used for when said second request module does not receive the state information of the normal operation of primary control program, and whether have main control module operation, if having, then close this main control module if detecting.Whether have the method for main control module operation be: through whether there being the running status sign corresponding programs of main window title or system banner and main control module in the api function detection system, if then judging has main control module if detecting; Otherwise, judge no master control module.
Module is set, is used for this monitoring module is set to main control module; The method that this monitoring module is set to main control module is: the running status sign of instance is set to the running status sign of main control module in this monitoring module; The main window title or the system banner of corresponding main control module are set for this instance; Create and monitoring module information interaction and the resource that the execution network service function needs for this instance, start network service function client.
The second adjacent instance starts module, is used to utilize the running environment sign of said adjacent instance to start the adjacent instance of operation.
This equipment also comprises:
Stopping modular 54 is used for stopping the running status inquiry of an instance of said two instances to adjacent instance; Obtain the handle of said adjacent instance, the api function that the operating system of utilizing this handle to call the said network server of operation provides utilizes this api function to close the program of said adjacent instance; Close the program of a said instance.
To sum up, beneficial effect of the present invention is:
In the scheme that the embodiment of the invention provides, through two instances of operational network service routine, the heat that forms primary control program, monitoring program mutual monitoring is equipped with network server.Do not need third-party monitoring software, the function that is only provided by network server itself realizes that mutual supervision, the network service function of two running examples transferred to non-malfunction routine, closes and restarted controls such as malfunction routine automatically by malfunction routine.
Scheme according to embodiment provides as long as two running environment with definite corresponding relation are set when mounted, during operation, can realize above-mentioned monitoring function.Otherwise, only as general network server operation, and need not do any change, have great flexibility in the use, the monitoring function of realization provides guarantee to the safe operation of network server, has remarkable result.