Operation and maintenance experience sharing as a topic, currently a total of 7 articles
-
Operation and maintenance experience sharing (i)--Linux Shell's Chatterserver service control script
-
Operation and maintenance experience Sharing (ii)--Linux Shell's Chatterserver service control script two times optimization
-
Operation and maintenance experience Sharing (iii)--solving the problem of crontab not executing shell scripts correctly under Ubuntu (i)
-
Operation and maintenance experience sharing (IV.)--the analysis of the programming of service control scripts for Java process Management
-
Operation and maintenance experience Sharing (v)-Improved Java Process Management Service control script
-
Operation and maintenance experience sharing (vi)--crontab The problem of shell scripting not being executed correctly (ii)
-
Operation and maintenance experience Sharing (vii)--Linux Shell's Chatterserver Service Control script third optimization
==================================== Split Line ======================================
Chatterserver has so many editions and encountered so many problems, and the Java process has a great relationship, the problem and analysis of the current situation is summarized as follows, welcome you to add.
Possible problems with stopping the Java process:
-
Stop the Java process as a kill PID, the Java process is waiting for the end of the Java process, so there is no immediate end, causing the original Java program to listen to the port may not be released, the original Java process PID may still exist
-
In the case where the original Java process did not end immediately, restarting the Java process would produce an error, including the inability to re-listen to the port or even the direct start failure
-
Possible issues with starting the Java process:
-
Start the Java process with the Java command, the Java process returns the result as a success, but the actual unsuccessful (need to be careful to confirm that "start Java process with java command" returned by the execution of Java itself returned, or manually written by the program returned)
Some further explanations, terms, and examples are described above:
-
Java process refers to a number of manually written Java programs, which do not guarantee that the program inside the exception is captured and processed, for example, if the port can not listen to return the correct error return value and exit
-
Kill pid mode: Kill ' Cat $PIDFILE '
-
Start the Java process with the Java command: Java-jar Somename.jar $ARGS
The original process of starting the Java process
-
There are two scenarios for starting a process, first starting (first boot), stopping the process from starting again (restarting), so consider combining the two scenarios to consider whether you have started or stopped before, taking into account
-
Determine if a PID file or lock exists in a specific directory on the current system
-
To determine whether a Java process exists in the current system, judging by whether the Java process PID is present from the system, such as PS, rather than the PID file or lock
-
Determine if the port number is already listening on the current system, because the port number may be used by another program (if the PID does not exist, the port number will not be occupied by itself)
-
Start the Java process (most programs will be guaranteed to start successfully here, can refer to/etc/init.d/functions, line 270,1-8), if the return result is successful, then the output is successful and create a PID file and lock, if unsuccessful, the output is unsuccessful, no longer try to start again
The original process of stopping the Java process
-
If the PID is found, send the term signal first, pause 100000 microseconds (usleep 100000), if the manual pre-known need to continue delay, then delay the custom number of seconds, if not killed (that is, still can detect the presence of this PID in the system) then send the kill signal, Pause 100000 microseconds again
-
The PID is detected again in the system, and if it does not, the output succeeds and the PID file and lock are removed and the output is unsuccessful if present
-
If the PID is not found, the output program is not running
Redesign the process for starting the Java process based on the above problem (main problem)
-
There are two scenarios for starting a process, first starting (first boot), stopping the process from starting again (restarting), so consider combining the two scenarios to consider whether you have started or stopped before, taking into account
-
Determine if a PID file exists in a specific directory in the current system (there is no lock in the original design, therefore no lock is used)
-
Determine whether the current system has a Java process, the basis is to detect from the system Java process PID exists, such as test-d/proc/$pid, PS, and not based on PID file or lock judgment
-
Determine if the port number is already listening on the current system, because the port number may be used by another program (if the PID does not exist, the port number will not be occupied by itself)
-
Start the Java process (most programs will be guaranteed to start successfully here, can refer to/etc/init.d/functions, line 270,1-8), if the return result is successful, from the system to detect the Java process PID exists, If the PID is present and the output is successful and the PID file is created (there is no lock in the original design, so the lock is not used), if the PID does not exist, start the Java process again and remove the "if unsuccessful, the output is unsuccessful and no longer attempts to start again."
Redesign the process to stop the Java process based on the above problems
-
For the possibility that the Java process does not kill, now make such a modification, if the PID is found, first send the term signal, pause 100000 microseconds (Usleep 100000), has been pre-aware of the need to continue delay, delay of 5 seconds, If it is not killed (that is, it still detects the presence of this PID in the system), send the kill signal again and pause for 100000 microseconds
-
The PID is detected again in the system, if it does not exist then the output succeeds and the PID file is removed (there is no lock in the original design, so no lock is used), if the PID persists then try Kill-9 (the signals SIGKILL and SIGSTOP cannot be Caught, blocked, or ignored. Current assumptions that 9 is more compelling than kill
-
If the PID is not found, the output program is not running
--end--
==================================== Split Line ======================================
Operation and maintenance experience sharing as a topic, currently a total of 7 articles
-
Operation and maintenance experience sharing (i)--Linux Shell's Chatterserver service control script
-
Operation and maintenance experience Sharing (ii)--Linux Shell's Chatterserver service control script two times optimization
-
Operation and maintenance experience Sharing (iii)--solving the problem of crontab not executing shell scripts correctly under Ubuntu (i)
-
Operation and maintenance experience sharing (IV.)--the analysis of the programming of service control scripts for Java process Management
-
Operation and maintenance experience Sharing (v)-Improved Java Process Management Service control script
-
Operation and maintenance experience sharing (vi)--crontab The problem of shell scripting not being executed correctly (ii)
-
Operation and maintenance experience Sharing (vii)--Linux Shell's Chatterserver Service Control script third optimization
This article is from "Communication, My Favorites" blog, please make sure to keep this source http://dgd2010.blog.51cto.com/1539422/1677155
Operation and maintenance experience Sharing (iv)--analysis of the programming of service control scripts for Java process Management