I need to start and restart a custom web server on travis. Starting in background is fine using a sub-shell (.travis.yml
):
- if [ "$TEST_ADAPTER" = "HTTP" ]; then (vendor/bin/httpd.php start &); fi
To stop/kill the process again I'm trying to get its PID and then kill it:
- if [ "$TEST_ADAPTER" = "HTTP" ]; then (vendor/bin/httpd.php start &) && SERVER_PID=$!; fi
- ...
- if [ "$TEST_ADAPTER" = "HTTP" ]; then kill -9 $SERVER_PID && ...; fi
However, SERVER_PID
is empty.
What is the right way to obtain the PID of a background process on travis in order to stop it (complication: without using an additional shell script)?