From 6beed011c20069438be900150c5465e5de734816 Mon Sep 17 00:00:00 2001 From: Ben Moss Date: Mon, 4 Nov 2019 12:16:59 -0500 Subject: [PATCH] Add drain script for docker-windows job --- jobs/docker-windows/spec | 1 + jobs/docker-windows/templates/drain.ps1 | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 jobs/docker-windows/templates/drain.ps1 diff --git a/jobs/docker-windows/spec b/jobs/docker-windows/spec index 6cb204d..124300a 100644 --- a/jobs/docker-windows/spec +++ b/jobs/docker-windows/spec @@ -3,6 +3,7 @@ name: docker-windows templates: pre-start.ps1: bin/pre-start.ps1 + drain.ps1: bin/drain.ps1 packages: - docker-windows diff --git a/jobs/docker-windows/templates/drain.ps1 b/jobs/docker-windows/templates/drain.ps1 new file mode 100644 index 0000000..673a6a5 --- /dev/null +++ b/jobs/docker-windows/templates/drain.ps1 @@ -0,0 +1,19 @@ +$ErrorActionPreference = "Stop"; + +echo "Querying docker service" | Out-File -Encoding ASCII -Append "c:\var\vcap\sys\log\docker-windows\drain.log" +$docker=(Get-Service | where { $_.Name -eq 'docker' }) +if ($docker -eq $null) { + echo "Docker service not found; Exiting 0" | Out-File -Encoding ASCII -Append "c:\var\vcap\sys\log\docker-windows\drain.log" + "0" + Exit 0 +} + +echo "Docker service found" | Out-File -Encoding ASCII -Append "c:\var\vcap\sys\log\docker-windows\drain.log" +If ($docker.Status -Eq "Running") { + echo "Docker service running; Stopping" | Out-File -Encoding ASCII -Append "c:\var\vcap\sys\log\docker-windows\drain.log" + Stop-Service $docker | Out-File -Encoding ASCII -Append "c:\var\vcap\sys\log\docker-windows\drain.log" +} +echo "Docker service drained; Exit 0" | Out-File -Encoding ASCII -Append "c:\var\vcap\sys\log\docker-windows\drain.log" + +"0" +Exit 0