Search code examples
bashubuntugitlabgitlab-ci-runner

gitlab runner gets stuck with background process


In Gitalb CI/CD, I want to start a server as a background process (Bash in Ubuntu). Gitlab-runner is type shell. I am using Ubuntu server and manually installed gitlab-runner. The problem is, if I start any background process, gitlab-runner is waiting for it as well. That is of course not the intention, since it shall start the server. I tried also with something very simple:

#!/bin/bash
echo "Starting background process."
sleep 900 &
echo "Finished."

The "Finished." appears immediately in the log, as expected. But gitlab-runner does not finish, waiting for the background sleep command as well (running into timeout). Without background process, it finishes normally.

How can I start a background process and yet finish gitlab-runner normally ?


Solution

  • I solved it myself. The reason seems to be that the background process, even if disowned, writes to STDOUT and obviously preventing with that to finish the job. The solution was to use nohup and redirect any output to /dev/null executing the script with server start command:

    nohup bash ./run.sh >/dev/null 2>&1 &
    

    Now the gitlab-runner finishes normally. Yet, this is still strange behavior from gitlab-runner.