From bee570a2f094824c7067108f0d7d17fff901e985 Mon Sep 17 00:00:00 2001 From: Yu-Ju Hong Date: Thu, 2 May 2019 18:52:31 -0700 Subject: [PATCH] GCE/Windows: force kill the stackdriver processes when necessary StackdriverLogging service sometimes cannot be stopped properly. This work around the bug by force killing the processes. --- cluster/gce/windows/k8s-node-setup.psm1 | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cluster/gce/windows/k8s-node-setup.psm1 b/cluster/gce/windows/k8s-node-setup.psm1 index 6f20f65d383..937c69dbe97 100644 --- a/cluster/gce/windows/k8s-node-setup.psm1 +++ b/cluster/gce/windows/k8s-node-setup.psm1 @@ -1079,6 +1079,22 @@ function Configure-Dockerd { $STACKDRIVER_VERSION = 'v1-9' $STACKDRIVER_ROOT = 'C:\Program Files (x86)\Stackdriver' + +# Restart the Stackdriver logging agent +# `Restart-Service StackdriverLogging` may fail because StackdriverLogging +# sometimes is unstoppable, so we work around it by killing the processes. +function Restart-StackdriverLoggingAgent { + Stop-Service -NoWait StackdriverLogging + # TODO: check periodically to lower the wait time + Start-Sleep 10 + if ((Get-service StackdriverLogging).Status -ne 'Stopped') { + # Force kill the processes. + Stop-Process -Force -PassThru -Id (Get-WmiObject win32_process | + Where CommandLine -Like '*Stackdriver/logging*').ProcessId + } + Start-Service StackdriverLogging +} + # Install and start the Stackdriver logging agent according to # https://cloud.google.com/logging/docs/agent/installation. # TODO(yujuhong): Update to a newer Stackdriver agent once it is released to @@ -1105,7 +1121,7 @@ function InstallAndStart-LoggingAgent { "Stackdriver logging agent is already installed") # Restart-Service restarts a running service or starts a not-running # service. - Restart-Service StackdriverLogging + Restart-StackdriverLoggingAgent return } @@ -1136,7 +1152,7 @@ function InstallAndStart-LoggingAgent { -Encoding ASCII # Restart the service to pick up the new configurations. - Restart-Service StackdriverLogging + Restart-StackdriverLoggingAgent Remove-Item -Force -Recurse $tmp_dir }