How to set location for Runner logs?

--------------------------------------------------------DISCLAIMER--------------------------------------------------------
What I wrote here, while it probably won’t, can have unknown consequences for your GitLab environment. You’re proceeding on your own responsibility.
--------------------------------------------------------DISCLAIMER--------------------------------------------------------

By default, Runner daemon logs go to syslog. I played around on my Ubuntu host:

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
$ busctl --system get-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager Version
s "245.4-4ubuntu3.2"
$ gitlab-runner --version
Version:      13.4.1
Git revision: e95f89a0
Git branch:   13-4-stable
GO version:   go1.13.8
Built:        2020-09-25T20:03:43+0000
OS/Arch:      linux/amd64

and managed to set different location for these logs.

I did it by modifying unit file (/etc/systemd/system/gitlab-runner.service). It ended up being as follows:

[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"
StandardOutput=file:/home/gitlab-runner/runner.log
StandardError=file:/home/gitlab-runner/runner.log
Restart=always
RestartSec=120
[Install]
WantedBy=multi-user.target

Essentially, I added:

StandardOutput=file:/home/gitlab-runner/runner.log
StandardError=file:/home/gitlab-runner/runner.log

and removed "--syslog" flag from ExecStart line.

Note that the systemd version (assuming your system is managed by it) is important here as it needs to be higher than 236 for some of the options I introduced in the unit file to work.

Once you do the above, you probably need to run systemctl daemon-reload and maybe even restart the runner with gitlab-runner restart for the changes to take effect.

4 Likes