Skip to content

Instantly share code, notes, and snippets.

@arcanemachine
Last active March 29, 2024 19:16
Show Gist options
  • Save arcanemachine/2fcf2d4a023d425e0330b99660f028f8 to your computer and use it in GitHub Desktop.
Save arcanemachine/2fcf2d4a023d425e0330b99660f028f8 to your computer and use it in GitHub Desktop.
How to set up `gitlab-runner` for a non-root user

Here's how I set up gitlab-runner for a non-root user inside a Vagrant VM (should work for non-VM machines as well):

  • Check to see if the process is running for the existing user:

ps aux | grep gitlab

  • If the process is running, it will look something like this after you run the previous command:

/usr/bin/gitlab-runner run --config /etc/gitlab/runner/config.toml --service gitlab-runner

  • Stop the existing gitlab-runner systemd service:

sudo systemctl stop gitlab-runner

  • The process should no longer appear if you type ps aux | grep gitlab again.

  • Uninstall the existing user's 'gitlab-runner' service:

sudo gitlab-runner uninstall

  • Reinstall the service for the new user:
sudo gitlab-runner install \
  --service gitlab-runner \
  --user $USER \
  --working-directory /home/$USER
  • Reload systemd daemons:

sudo systemctl daemon-reload

  • Start the new user's gitlab-runner systemd service:

sudo systemctl start gitlab-runner

  • To ensure the service runs on boot:

sudo systemctl enable gitlab-runner

  • Check to see if the process is running for the new user:

ps aux | grep gitlab

  • The new process should look something like this (I used Vagrant for this, so my user is vagrant):

/usr/bin/gitlab-runner run --working-directory /home/vagrant --config /etc/gitlab-runner/config.toml --service gitlab-runner --user vagrant

  • Run gitlab-runner as your new user:

gitlab-runner exec shell some_job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment