Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I run a runner as a service on linux?

ryanjmp
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!
October 25, 2023

I've installed a runner on my linux instance, but it will only work while I am ssh'd into the machine.  If I close my terminal session, the runner no longer works.  How can I have the runner always running?

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 27, 2023

Hello @ryanjmp and welcome to the Community!

If you are referring to Linux Shell runners, you can run it as a service/daemon by configuring the runner in systems. Systemd service will run in the background and will not require your session to be active. It will also automatically start the runner service when the host is booted.

Following are the instructions on how to configure it : 

  1. Open a terminal session in the runner's host and create a system unit file :
    sudo nano /lib/systemd/system/bitbucketrunner.service 
  2. Add the following content to the file : 
    [Unit]
    Description=Bitbucket Runner Service
     
    [Service]
    WorkingDirectory=/home/ubuntu/atlassian-bitbucket-pipelines-runner/bin/
    ExecStart=/home/ubuntu/atlassian-bitbucket-pipelines-runner/bin/start.sh --accountUuid {REDACTED} --repositoryUuid {REDACTED} --runnerUuid {REDACTED} --OAuthClientId REDACTED --OAuthClientSecret REDACTED --runtime linux-shell --workingDirectory ../temp

    [Install]
    WantedBy=multi-user.target

    where : 

    WorkingDirectory : the absolute path to bin folder where you extracted the runner in the host.

    ExectStart : the runner start.sh script command you received when you created the runner. Please note the path to the script must be an absolute path (start from / ), as systemd does not support relative paths ( like home directory ~).

  3. Reload systemd to read the new service created : 
    sudo systemctl daemon-reload
    Whenever you make any changes to the .service file, you will need to reload the daemon for the changes to take effect.

  4. Enable the service to start on the system boot
    sudo systemctl enable bitbucketrunner.service
  5. Start the service
    sudo systemctl start bitbucketrunner.service  
  6. Verify if the runner started successfully by checking the status of the service
    sudo systemctl status bitbucketrunner.service 

If the service status reports that the runner started successfully, you can check the runner state in the UI as it should be showing as Online already, which means it's ready to run your pipelines :) 

Hope that helps! If you have any questions, feel free to ask.

Thank you, @ryanjmp !

Patrik S

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events