Gracefully exiting UI Application via Tentacle?

Hey there,

I’m trying to figure out how to gracefully update some legacy applications with Octopus.

Scenario:

  • some of our servers have to run Windows applications that require a GUI and an active windows session. It’ll be around 1-2 years until this is replaced by a service application which is why I have to find a safe way.
  • so far updating works fine when running a powershell script that forcibly closes the application. This is part of the projects process before deploying. However, a forced exit can result in invalid data etc.pp. It’s just not a nice way to exit and introduces quite a bit of risk.
    The script (part of it) uses this command:
    Get-Process $app -ErrorAction SilentlyContinue -IncludeUserName| Where UserName -match $user | Stop-Process -Force

I do know that PowerShell offers an option to gracefully close an application as if the user exited the application and, given that no user interaction is required (like “do you want to save?”, which the application doesn’t have, luckily) this works fine when running it directly on that machine via Powershell:

Get-Process $app -ErrorAction SilentlyContinue -IncludeUserName| Where UserName -match $user | Foreach-Object { $_.CloseMainWindow()}

Running the same command via the tentacle doesn’t work.
This is probably partly because Windows won’t let scripts from session A interact with interactive applications on session B. That would be true in a standard setup with the application running in a session of User_X and the tentacle running as a service as the “Local System” user.

I tried running the tentacle service with the same Windows user as the application but didnt have any success.

I’m aware that this is likely not a 100% Octopus related issues, I just wondered if you have any sort of experience with this and a recommendation on how to acchieve a graceful shutdown of the application.

There are option with a lot of overhead (e.g. creating a scheduled task via powershell to exit the GUI, etc.) but I don’t really want to go down that route.

Happy to hear any thoughts and suggestions from your side.

Thanks,
Chris

Hi Chris,

Unfortunately my testing also came up with the same problems as you encountered, and any workaround I could think of quickly ran into the you can't elevate remote scripts security block that Powershell has.

Sorry that I can’t be of more help,

Regards
Alex

Hey Alex,

thanks for your efforts and reply. I guess I’ll have to take the route of doing it via a dynamically created scheduled task then Sadly, MS doesn’t allow for this any other way.

Best regards,

Chris

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.