Have graceful termination out of the box for gitlab-runner install

Overview

When you run gitlab-runner install inside of a Linux machine this creates a systemd service gitlab-runner.service with the contents below:

cat /etc/systemd/system/gitlab-runner.service
[Unit]
Description=GitLab Runner
After=syslog.target network.target
ConditionFileIsExecutable=/usr/bin/gitlab-runner

[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/usr/bin/gitlab-runner "run" "--working-directory" "/home/gitlab-runner" "--config" "/etc/gitlab-runner/config.toml" "--service" "gitlab-runner" "--user" "gitlab-runner"





Restart=always
RestartSec=120

[Install]
WantedBy=multi-user.target

By default systemd sends a SIGTERM which requires used to create a drop-in file with the following content since gitlab-runner doesn't understand SIGTERM but understand SIGQUIT for graceful termination.

[Service]
TimeoutStopSec=7200
KillSignal=SIGQUIT

Proposal

There are two things that we can do:

  1. Have gitlab-runner listen to SIGTERM as well for graceful termination.
  2. Specify KillSignal=SIGQUIT when you run gitlab-runner install on a Linux machine so that it's terminated gracefully by default.