[英]Is there a way to tell if a Jenkins server has finished shutting down?
I am running Jenkins on a virtual machine and calling the cli from a batch file to do a safe shutdown like so: 我在虚拟机上运行Jenkins,并从批处理文件中调用cli进行安全关机,如下所示:
java -jar $JenkinsCLILocation -s http://$JenkinsURL safe-shutdown
Once it's finished shutting down, I'm turning off the virtual machine and cloning it. 关闭完成后,我将关闭虚拟机并进行克隆。 However, I don't want to turn off the virtual machine before the safe shutdown of Jenkins is complete.
但是,我不想在安全关闭Jenkins之前关闭虚拟机。 Is there any way I can monitor the Jenkins using either the cli or a batch command to see if it's properly shut down?
有什么方法可以使用cli或批处理命令监视Jenkins,以查看是否已正确关闭?
This is the most ghetto hack. 这是最贫民窟的黑客。 What I'm basically doing is looking at the error output from the java command that executes the Jenkins CLI jar file, and if the error output contains "Failed to connect", I assume that the Jenkins has been shut off.
我基本上正在做的是查看执行Jenkins CLI jar文件的java命令的错误输出,如果错误输出包含“无法连接”,则我认为Jenkins已关闭。
I would love to see if anyone has a more graceful solution, cause man, this is just gross. 我很想看看是否有人有一个更优雅的解决方案,因为伙计,这简直太过分了。
while(!$JenkinsIsDown)
{
Write-Host "Getting the session ID from Jenkins to check if it's down..."
#This is a terrible hack so we can process the output of the command
$JenkinsProcess = New-Object System.Diagnostics.ProcessStartInfo
$JenkinsProcess.FileName = "java"
$JenkinsProcess.RedirectStandardError = $true
$JenkinsProcess.RedirectStandardOutput = $true
$JenkinsProcess.UseShellExecute = $false
$JenkinsProcess.Arguments = "-jar " + $JenkinsCLILocation + " -s http://" + $JenkinsURL + " session-id"
$JenkinsProcess.WaitForExit()
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $JenkinsProcess
$p.Start() | Out-Null
$p.WaitForExit()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
if($stderr.Contains("Failed to connect"))
{
Write-Host "The Jenkins is down."
$JenkinsIsDown = $true
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.