How to start an external processes that doesn't end
Completed
Hi,
Im trying to run a script that starts a python webserver in a teamcity step. If I put the commands directly in the runner, the step hangs forever. If I fork it using start-process, it seems to end instantly.
What I'm trying to do is create a pipeline to run some api tests, however I need the webserver up and running beforehand. How could I do this? My teamcity setup is really simple, 1 server, agent on same server, running on local hardware so Im able to hardcode paths to executables etc if I need to, and run git commands to update code, outside of the Teamcity framework
Thanks,
Please sign in to leave a comment.
Hi, you can try starting a process in a screen. Something like this in a command-line build step should run a detached screen with simple python webserver running:
screen -d -m python3 -m http.server 8000 --bind 127.0.0.1
thanks! Unfortunately we're still running on windows hardware atm, (in the process of migrating) will this work if teamcity is installed on a windows box?
Hi Mike,
I expect this to work if you install the Windows Subsystem for Linux.
It should also be possible in a more windows-way, say if you configure your web server as a service. Then you should be able to just start the service via command-line assuming the user running the agent has proper permissions. It might also be possible using Windows Script for the same, here are some relevant links, which might help you to achieve your goal:
https://stackoverflow.com/questions/21031171/how-to-run-a-command-on-the-background-on-windows
https://serverfault.com/questions/9038/run-a-bat-file-in-a-scheduled-task-without-a-window
I see, thanks, so if I were to change my cmd prompt to launch wsl first, and then run, with screen it might work? I shall see if I'm allowed to install WSL onto this server.
I've tried using powershell start-process, however whilst it works locally (ie manually running, and closing the parent window), teamcity seemed to kill all child jobs started
Hi Mike,
You're right that TeamCity Agent tries to kill all child jobs started when it finishes its work - it attempts to clean-up after itself. So for a process to be left alive, we need to amend its parent process so that the Agent will "lose" it from the cleanup scope. Using screen is one way to do it.