solution with Ubuntu (Linux) run command

sudo crontab -e

Important -> sudo give possibility run crontab tasks as root (sudoer user) Add in crontab tasks command below

@reboot sudo gitlab-runner run

On each server reboot gitlab-runner will be started

Answer from Mmx on Stack Overflow
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
Runner Not running as service - GitLab CI/CD - GitLab Forum
September 18, 2023 - I just recently installed gitlab and went to go deploy runners. I created a runner and followed the steps to try to get it to run as a service. The service is running and it says it loads the config and initializing executor. Yet with the service running it doesn’t pull jobs.
Discussions

Gitlab runner launches applications in the background
I’m working with Windows runner and shell executor. Gitlab runner launches applications in the background. Is there any way for gitlab to launch them in the foreground? More on forum.gitlab.com
🌐 forum.gitlab.com
1
0
November 7, 2018
Gitlab Continuous Integration npm Background Process - Stack Overflow
Do you have experience in running background tasks with gitlab runner? ... My use case would be launching a web service in a background process and testing it using selenium tests and having the runner shutdown with the service when the tests are done. I simple proof of concept would be launching a php simple server process in a background process and pinging it or curling until the page is ready or max time out. ... I think the best solution would be to use some service manager (systemd, runit... More on stackoverflow.com
🌐 stackoverflow.com
gitlab-runner only run pipeline when `gitlab-runner run` is on
I registered a runner on local gitlab environment. The runner will only execute the pipeline when there is a process is running the command of gitlab-runner run. Once the process stops running the command, jobs will remain pending. It is a linux(ubuntu) runner with shell executor, I tried to ... More on forum.gitlab.com
🌐 forum.gitlab.com
2
0
November 23, 2023
How to make private gitlab runner display job logs and info in the console as jobs are run?
On selfhosted instances you can watch the job logs live as they run from the gitlab interface? And see the same afterwards too? Unsure how it works with gitlab.com More on reddit.com
🌐 r/gitlab
3
4
March 24, 2023
🌐
YouTube
youtube.com › watch
How to Run GitLab Runner in the Background on Ubuntu Startup - YouTube
Learn how to configure GitLab Runner to automatically start on Ubuntu system boot, ensuring your CI/CD processes are always up to date.---This video is based...
Published: April 7, 2025
Views: 30
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
Gitlab runner launches applications in the background - GitLab CI/CD - GitLab Forum
November 7, 2018 - I’m working with Windows runner and shell executor. Gitlab runner launches applications in the background. Is there any way for gitlab to launch them in the foreground?
🌐
GitLab
gitlab.com › gitlab.org › gitlab-runner › #3228
Gitlab-CI times out whenever a process runs in background (#3228) · Issues · GitLab.org / gitlab-runner · GitLab
April 16, 2018 - Summary Any Gitlab CI script with a running process on background, such as a process started on the before_script section, freezes...
🌐
Awsstudygroup
000017.awsstudygroup.com › 3-cicd-gitlab › 2-setupgitlabandrunner
Install and Register GitLab Runner :: DEPLOY APPLICATIONS WITH CI/CD PIPELINE ON AMAZON ELASTIC CONTAINER SERVICE
# Register runner with token gitlab-runner register --url https://gitlab.com --token [your-token] # Enter information when prompted - URL: https://gitlab.com - Name: fcj-lab-runner-be - Executor: shell · Start Runner · # Run in background nohup gitlab-runner run > start-runner-be.txt 2>&1 & # Check logs tail -f start-runner-be.txt ·
🌐
YouTube
youtube.com › watch
How to Efficiently Run GitLab Runner in the Background for Testing - YouTube
Struggling to test your GitLab Runner? Discover how to run the `gitlab-runner` service in the background and streamline your testing process.---This video is...
Published: May 27, 2025
Views: 3
Find elsewhere
Top answer
1 of 2
12

According to Tomasz Maczukin on a related GitLab issue:

I think the best solution would be to use some service manager (systemd, runit, upstart, sysv - whatever is present on this system).

On the server you should prepare configuration file to start the service. Then in CI job you would do e.g. systemctl start tomcat. This command is expected to exit just after calling and it's service manager (outside of Runner's scope) who starts the process.

Process started with Runner, even if you add nohup and & at the end, is marked with process group ID. When job is finished Runner is sending kill signal to whole process group. So any process started directly from CI job will be terminated at job end. Using service manager you're not starting the process in context of Runner's job. Your only notifying a manager to start a process using prepared configuration :)

2 of 2
8

Here is an example of running a process in the background using the systemd service manager.

In this example, Gitlab CI/CD will deploy a React web app in an HTTP server running on Ubuntu.

Step 1: On the runner, create a service unit file

vi /etc/systemd/system/hello-react.service

[Unit]
Description=Hello React service
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=gitlab-runner
ExecStart=npx http-server -p 3000 /home/gitlab-runner/hello-react/

[Install]
WantedBy=multi-user.target

Step 2: On the runner, grant the sudo permission to user gitlab-runner with no password restriction.

$ sudo usermod -a -G sudo gitlab-runner
$ sudo visudo

Now add the following line to the bottom of the file

gitlab-runner ALL=(ALL) NOPASSWD: ALL

Step 3: In your code repo, create deploy.sh

#!/bin/bash

echo "Build the app for production"
npm run build

echo "Copy over the build"
rm -fr /home/gitlab-runner/hello-react/*
cp -r build/* /home/gitlab-runner/hello-react/

echo "Running server in the background"
sudo systemctl restart hello-react

echo "HTTP server started."

Step 4: In your code repo, update .gitlab-ci.yml

image: node:latest

stages:
    - build
    - test
    - deploy

cache:
    paths:
        - node_modules/

install_dependecies:
    stage: build
    script:
        - npm install

    artifacts:
        paths:
            - node_modules/
run_unit_tests:
    stage: test
    script:
        - npm test

deploy_app:
    stage: deploy
    script:
        - bash -c './deploy.sh'

That's it. The CI/CD job will finish without halting. The app will be deployed, and you can visit it at http://your-server-ip:3000

🌐
GitLab
forum.gitlab.com › how to use gitlab
gitlab-runner only run pipeline when `gitlab-runner run` is on - How to Use GitLab - GitLab Forum
November 23, 2023 - I registered a runner on local gitlab environment. The runner will only execute the pipeline when there is a process is running the command of gitlab-runner run. Once the process stops running the command, jobs will rem…
🌐
GitLab
gitlab.com › gitlab.org › gitlab-runner › #2880
CI job scripts do not complete when dockerd or any process runs in the background (#2880) · Issues · GitLab.org / gitlab-runner · GitLab
November 12, 2017 - Summary script never finishes when dockerd was started in background. Possibly the same with any kind of process running in the...
🌐
Jfreeman
jfreeman.dev › blog › 2019 › 03 › 22 › understanding-gitlab-runner
John Freeman | Understanding GitLab Runner
March 22, 2019 - When you install gitlab-runner, know that it is generally installed as a long-running background service.
🌐
GitLab
gitlab.com › gitlab.org › gitlab-runner › #2231
build job running forever when executing a script to start tomcat service (#2231) · Issues · GitLab.org / gitlab-runner · GitLab
March 13, 2017 - ![123](/uploads/5de123b9caed37463cb47ed838a49433/123.jpg) open debug model: # gitlab-ci-multi-runner --debug run some error occurred. ![321](/uploads/2d3b710aa0d5996ffebdf998ec0b75d7/321.jpg) ## Expected behavior I want the service to start running in the background,and build success instead ...
🌐
GitLab
docs.gitlab.com › gitlab docs › install › configure gitlab runner › commands
GitLab Runner commands | GitLab Docs
NAME: gitlab-runner run - run multi runner service USAGE: gitlab-runner run [command options] [arguments...] OPTIONS: -c, --config "/Users/ayufan/.gitlab-runner/config.toml" Config file [$CONFIG_FILE] When you’re looking for the cause of an undefined behavior or error, use debug mode. To run a command in debug mode, prepend the command with --debug:
🌐
GitLab
forum.gitlab.com › how to use gitlab
Runner as daemon - How to Use GitLab - GitLab Forum
August 9, 2018 - Why I need execute sudo gitlab-runner run for every deploy? How I can start it with boot system in background?
🌐
GitHub
gist.github.com › DrPsychick › b92c2653c1132c3be6da2c3bb42905d4
Run gitlab-ci jobs locally · GitHub
docker run --rm -d \ --name gitlab-runner \ -v $PWD:$PWD \ -v /var/run/docker.sock:/var/run/docker.sock \ gitlab/gitlab-runner:latest · If you use template jobs (.test) then specify those as job. docker exec -it -w $PWD gitlab-runner gitlab-runner exec docker <job> ... SSH into Rancher VM: LIMA_HOME="$HOME/Library/Application Support/rancher-desktop/lima" "/Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/lima/bin/limactl" shell 0
🌐
GitLab
gitlab.com › gitlab.org › gitlab-runner › merge requests › !4162
Kubernetes executor: prevent background processes from hanging the entire job (!4162) · Merge requests · GitLab.org / gitlab-runner · GitLab
This works well most of the time, but if the executed script also starts processes in the background, they'll inherit the tee pipe as their standard output & error file descriptors. This means that when the parent command terminates, if these background processes survive, then the tee process never ends up getting EOF, blocking the shell we are attaching to. ... Which causes the problematic command to be run in a background subshell, and means we don't wait on a potentially blocked tee.