How to run multiple self-hosted runners on a single host

We’re using self-hosted runners in our organization and it’s working fine. What I want to do now is use bigger instances and run multiple runners per host.

I have a script that uses a PAT to generate a runner token, and then uses that token to start a runner. When I run the script multiple times on the same host, only one will register correctly. I get errors like:

A session for this runner already exists.
2020-09-03 19:26:14Z: Runner connect error: The actions runner 94e9c2e0ca90995c7764c845 already has an active session for owner ip-20-10-43-71.. Retrying until reconnected.

or

Cannot configure the runner because it is already configured. To reconfigure the runner, run 'config.cmd remove' or './config.sh remove' first.

I have noticed that the token I get from the token registration endpoint is the same for each runner I try to launch. While this might be the issue, I see no way to “force” the generation of a new registration token.

I should also mention using a different (randomly-generated) --name and --workdir when I run config.sh.

Hi @dmerrick,

Glad to see you in Github Community Forum!

The error should be due to you didn’t change the directory for the configuration script(config.sh/config.cmd), please change to another workdir for new configuration.

To install multiple self-hosted runner on your host, you should use different workdir and different runner name. The registration token can be identical( or you can rerun the api command to get a new one).

These runners are using same machine env and disk, it’s recommened to create them on different VMs on your host to seperate them.

Thanks

Thank you, I was able to get this working by running config.sh from different directories for each worker.

Hi Dmerrick,

I tried to run multiple runners on my self-hosted runners as well. I am getting the below error. Even then I used different working directories for different runners. Could you please let me know what mistake I am doing?

Cannot configure the runner because it is already configured. To reconfigure the runner, run ‘config.cmd remove’ or ‘./config.sh remove’ first.

Hey Pradeep,

I’ve got a setup working for starting multiple self-hosted runners on the same host, for different repositories.

I have a directory for each repository, and extract the actions runner .tar into each one separately. I generate a token and then run the config.sh inside each directory.

So my file structure looks something like:
base/
|-dir1
|-|-config.sh
|-dir2
|-|-config.sh

If you’ve got a similar setup, then one thing you may want to check is whether or not you’re using the “–name” positional argument for config.sh. You need to make sure each one has a unique name.

Eg:

./config.sh --name <unique_name> --url …

Hope this helps!

Thanks for the reply Rahul. I wanted two runners for the same repo, is it possible?

Yep it is possible, I’ve tested it.

Just make sure you run config.sh out of separate directories, and make the runner names unique!

OK, thanks Rahul, I will have a look.

@ rahul-kumar-saini can you please share some examples of how to deploy multiple runners on a single host for single repository different branches.

My scenario is like, I have an ubuntu server where I want to access the develop branch and production branch separately.

Thanks