Skip to content

Instantly share code, notes, and snippets.

@f-steff
Created March 14, 2021 16:25
Show Gist options
  • Save f-steff/39892cdb60910a1aa9c39a6c4ed7aa4d to your computer and use it in GitHub Desktop.
Save f-steff/39892cdb60910a1aa9c39a6c4ed7aa4d to your computer and use it in GitHub Desktop.
Workaround to JENKINS-47657, restarting the service whenever it stops.
@echo off
:: 2019-03-20: Flemming Steffensen added this as a workaround to a Jenkins bug JENKINS-47657
:: https://issues.jenkins.io/browse/JENKINS-47657?focusedCommentId=363147&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-363147
::
set "ServiceName=jenkinsslave-C__Jenkins"
for /F "tokens=3 delims=: " %%H in ('sc query "%ServiceName%" ^| findstr " STATE"') DO (
if /i "%%H" neq "RUNNING" (
net start "%ServiceName%"
)
)

Some of our Win-10 Jenkins agents were very seriously affected by JENKINS-47657, and was going offline for no apparenty reason several times per day.

As a workaround, I added a batch script (EnsureJenkinsServiceRunnning.cmd) to check the status of the service every 10 minutes, and restarting the service if stopped. The script was published in this comment. Unfortunately the problem has still not been fixed and have just been de-prioritized even more (no longer assigned to anybody) which is why I also add it here.

The batch must be scheduled by Windows Schedule Tasks service, and set to run as a high priority task whenever the computer starts. Note the script must be run by at least a local administrator.

Note: This script can be used to restart any service that for one reason or another suddenly quits when it shouldn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment