Windows Server 2012R2 PowerShell 4.0
In case the Java process stops in the middle and cannot proceed to the subsequent job, the script may put a forced stop after the process is stopped. If there are multiple Java processes in the same OS on Windows, taskkilling by specifying the name (java.exe) will drop all Java processes. If you want to stop a specific Java process, identify it by process ID (PID), but here we are trying to force stop using a PID file.
After executing the Java stop command, add the following.
javakill.ps1
#PID file path-IBM WAS example-
$pid_file = "${install_root}/profiles/${profile_name}/logs/${server_name}/${server_name}.pid"
if(test-path $pid_file){
#If the process still remains, kill it and delete the pid file
write-output "Kill process:${server_name}"
$pid = get-content $pid_file
stop-process $pid -force
remove-item $pid_file
}else{
#Do nothing if the process has already stopped normally
write-output "process:${server_name} was already stopped:"
}
Please note that the output location of the Java PID file differs depending on the product. In IBM WAS-based products, the PID file is generated when the Java process is started and deleted when the Java process is stopped. Therefore, the PID file should also be deleted during the forced stop so that it will not be affected at the next startup.
http://qiita.com/opengl-8080/items/bb0f5e4f1c7ce045cc57 http://labunix.hateblo.jp/entry/20121108/1352378556 https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014801453#77777777-0000-0000-0000-000014810269
Recommended Posts