Bitbucket self hosted runner autostart

Karolis Milieska
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 22, 2021

Hello,

I have followed guide how to start self hosted bitbucket runner here: https://support.atlassian.com/bitbucket-cloud/docs/runners/

I now have docker command to start my runner on my server and it works as expected, builds are running.

docker container run -it -v /tmp:/tmp -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker/containers:/var/lib/docker/containers:ro -e ACCOUNT_UUID={<masked>} -e REPOSITORY_UUID={<masked>} -e RUNNER_UUID={<masked>} -e RUNTIME_PREREQUISITES_ENABLED=true -e OAUTH_CLIENT_ID=<masked> -e OAUTH_CLIENT_SECRET=<masked> -e WORKING_DIRECTORY=/tmp --name runner-<masked> docker-public.packages.atlassian.com/sox/atlassian/bitbucket-pipelines-runner:1

Now I need to make it headless, so that I would not need to start runner manually using command line every time my server restarts.

Is there any official documentation how to do that?

I know this might me basic docker question, but I would like to know the way how to do it like Atlassian intends.

1 answer

1 accepted

0 votes
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 24, 2021

Hello Karolis,

Welcome to Atlassian Community!

Unfortunately, at this moment there's no official Atlassian documentation on how to auto-start the runner's container after system restart, but you can refer to the official docker documentation about container restarting policies.

Docker provides different restarting policies that will dictate if your containers will be automatically started when they exit or when the docker daemon restarts. Following you have all the current available policies :

Flag

Description

no

Do not automatically restart the container. (the default)
on-failure Restart the container if it exits due to an error, which manifests as a non-zero exit code.
always Always restart the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted.

unless-stopped

Similar to always, except that when the container is stopped (manually or otherwise), it is not restarted even after Docker daemon restarts.

To setup a restarting policy in a given container you can use the --restart option and provide one of the flags above, accordingly to your use case.

Since you've mentioned you want your containers started after every server restart, I'd suggest using the --restart=always option, by following one of the below suggestions :

  • If you are creating a new runner container, you can edit the docker command we provide and add the --restart option
docker container run -it --restart=always -v [.....] --name runner-<masked> docker-public.packages.atlassian.com/sox/atlassian/bitbucket-pipelines-runner:1
  • If you already have the runner container created, you can update it's restart policy using the command:
docker update --restart=always <runner container name>

Please, let me know if you run into any issues trying one of my suggestions above.

Best regards,

Patrik S

Ajay _view26_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2021

Interesting usecase!

Like Patrik S likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events