From 50754b5eff4bb73ce9c1664fb9347ba3659b534d Mon Sep 17 00:00:00 2001 From: Scott Beddall <45376673+scbedd@users.noreply.github.com> Date: Thu, 14 Mar 2024 13:08:23 -0700 Subject: [PATCH] Add Proxy Shutdown Script (#7877) * create necessary eng/common changes to allow proxy to be shut down. --- eng/common/testproxy/test-proxy-tool-shutdown.yml | 10 ++++++++++ eng/common/testproxy/test-proxy-tool.yml | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 eng/common/testproxy/test-proxy-tool-shutdown.yml diff --git a/eng/common/testproxy/test-proxy-tool-shutdown.yml b/eng/common/testproxy/test-proxy-tool-shutdown.yml new file mode 100644 index 00000000000..20e24e70a0a --- /dev/null +++ b/eng/common/testproxy/test-proxy-tool-shutdown.yml @@ -0,0 +1,10 @@ +steps: + - pwsh: | + Stop-Process -Id $(PROXY_PID) + displayName: 'Shut down the testproxy - windows' + condition: and(succeeded(), eq(variables['Agent.OS'],'Windows_NT')) + + - bash: | + kill -9 $(PROXY_PID) + displayName: "Shut down the testproxy - linux/mac" + condition: and(succeeded(), ne(variables['Agent.OS'],'Windows_NT')) diff --git a/eng/common/testproxy/test-proxy-tool.yml b/eng/common/testproxy/test-proxy-tool.yml index 7aea55d472d..d9a16684192 100644 --- a/eng/common/testproxy/test-proxy-tool.yml +++ b/eng/common/testproxy/test-proxy-tool.yml @@ -1,3 +1,4 @@ +# This template sets variable PROXY_PID to be used for shutdown later. parameters: rootFolder: '$(Build.SourcesDirectory)' runProxy: true @@ -42,15 +43,20 @@ steps: condition: and(succeeded(), ${{ parameters.condition }}) - pwsh: | - Start-Process $(Build.BinariesDirectory)/test-proxy/test-proxy.exe ` + $Process = Start-Process $(Build.BinariesDirectory)/test-proxy/test-proxy.exe ` -ArgumentList "start --storage-location ${{ parameters.rootFolder }} -U" ` -NoNewWindow -PassThru -RedirectStandardOutput ${{ parameters.rootFolder }}/test-proxy.log + + Write-Host "##vso[task.setvariable variable=PROXY_PID]$($Process.Id)" displayName: 'Run the testproxy - windows' condition: and(succeeded(), eq(variables['Agent.OS'],'Windows_NT'), ${{ parameters.condition }}) # nohup does NOT continue beyond the current session if you use it within powershell - bash: | nohup $(Build.BinariesDirectory)/test-proxy/test-proxy &>$(Build.SourcesDirectory)/test-proxy.log & + + echo $! > $(Build.SourcesDirectory)/test-proxy.pid + echo "##vso[task.setvariable variable=PROXY_PID]$(cat $(Build.SourcesDirectory)/test-proxy.pid)" displayName: "Run the testproxy - linux/mac" condition: and(succeeded(), ne(variables['Agent.OS'],'Windows_NT'), ${{ parameters.condition }}) workingDirectory: "${{ parameters.rootFolder }}"