How to start a long running console app as part of octopus deploy step?

I have a console app that is a long running process, when started it sits and listens for work indefinitely until its told to exit (yes ideally it would be a Windows Service but currently this is what we have and changing it is non-trivial). It is deployed to the target server as part of a “Deploy a package” step. The package is deployed and extracted as expected by Octopus what I’m hoping to get insight on is guidance on how to start the app.

My thinking was the right tool for the job was the powershell “Start-Process” command and to include the command at the appropriate place in the octopus deployment. The issue I’ve encountered is that the process is started but the deployment never completes because it appears the started process blocks the Octopus deployment process and it wont continue until the process that has been started is stopped. I’ve tried including the script in a Deploy.ps1 file in the package, and have also tried specifying the startup script in the custom post-deploy section of the deploy a package step.

Is this a supported scenario ?

Theres an old post on these forums from 2015 of a user encountering the same issue but its unclear if it was a bug or user error: https://help.octopus.com/t/long-running-console-applications/10408

Hi @jer.fer,

Thanks for getting in touch!

As you mention, this kind of deployment isn’t the ideal situation so Octopus may not handle it as desired.
Start-Process is the route I would go down, and I setup a quick test for it, and it does seem to act as expected.
I created sleep.ps1 with contents of Start-Sleep -s 400
Then added a script step to my deployment process to run start-process powershell -argument "C:\test\sleep.ps1"
When deploying, the deployment completes as soon as the command is run and doesn’t wait for the timer to expire.

The user in that linked topic does suggest that they do see different behaviour when running a .exe though, so this may be what you’re seeing.
The workaround they suggested is probably the best option you’re going to find for this:

The workaround seems to be to wrap the EXE with the windows task scheduler and have Octopus manage the scheduler for starting the service instead of starting the EXE directly

Regards,
Paul

The approach you mention @paul.calvert is slightly different than the one I tried. I used Start-Process to run my command directly (example: Start-Process MyApp.exe) instead of launching it from another powershell session. Are you able to create a quick console app with just a Console.ReadKey() statement to cause it to run indefinitely? I’m curious what behavior you see.

1 Like