Last active
February 5, 2018 16:35
-
-
Save idkaaa/4a508d7ddeaaccb86b26ae4360737c15 to your computer and use it in GitHub Desktop.
A powershell script that forces jira service off and then on again.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$thisDirectory = "C:\JIRA"; | |
$logPath = "$thisDirectory\restartLog.log"; | |
Function LogWrite | |
{ | |
Param ([string]$logString) | |
$dateString = "$(Get-Date -Format u)"; | |
$outputString = "$dateString $logString"; | |
Write-Host $outputString; | |
Add-content $logPath -value $outputString; | |
} | |
$serviceName = "JIRA240114184356"; | |
$startServiceDirectory = "C:\JIRA\JIRA"; | |
$startServiceCommandArgs = "C:\JIRA\JIRA\start_service.bat"; | |
LogWrite "Searching for PID for service: $serviceName"; | |
$servicePID = (get-wmiobject win32_service | where { $_.name -eq $serviceName}).processID; | |
if($servicePID -eq 0) | |
{ | |
LogWrite "PID not found for service: $serviceName."; | |
LogWrite "$(Get-Date -Format u) - Starting service: $serviceName..."; | |
cmd.exe /c $startServiceCommandArgs; | |
exit 0; | |
} | |
LogWrite "Attempting to stop service: $serviceName PID: $servicePID"; | |
$stopServiceCommandArgs = "taskkill /T /F /PID $servicePID"; | |
cmd.exe /c $stopServiceCommandArgs; | |
LogWrite "Waiting for 10 seconds..."; | |
Start-Sleep -s 10; | |
cd $startServiceDirectory; | |
LogWrite "$(Get-Date -Format u) - Starting service: $serviceName..."; | |
cmd.exe /c $startServiceCommandArgs; | |
LogWrite "Successfully started service: $serviceName"; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment