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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,582
Community Members
 
Community Events
184
Community Groups

Start and restart Windows self-hosted runner automatically

Hi

I've successfully set up a self-hosted runner on a Windows Server 2019 VM. How would you set it up so that it starts on boot and restarts on failure?

 

2 answers

1 accepted

Ok, this is what I did. Assuming we have the agent in d:\bb...

 


Download for windows: commons-daemon-1.3.2-bin-windows.zip from: https://downloads.apache.org/commons/daemon/binaries/windows/

Then copy these files (I use the x64 version):
Copy-Item amd64/prunsrv.exe d:\bb\bin\
Copy-Item prunmgr.exe d:\bb\bin\
New-Item -ItemType Directory -Path d:\bb\logs

Create an install.ps1 file in d:\bb\bin
param (
    [string]$accountUuid = $(throw "-accountUuid is required."),
    [string]$repositoryUuid = "",
    [string]$runnerUuid = $(throw "-runnerUuid is required."),
    [string]$OAuthClientId = $(throw "-OAuthClientId is required."),
    [string]$OAuthClientSecret = $(throw "-OAuthClientSecret is required."),
    [string]$workingDirectory = $(throw "-workingDirectory is required."),
    [string]$serviceUser = $(throw "-serviceUser is required."),
    [string]$servicePassword = $(throw "-servicePassword is required."),
    [string]$runnerEnvironment = "PRODUCTION",
    [string]$scheduledStateUpdateInitialDelaySeconds = "0",    
    [string]$scheduledStateUpdatePeriodSeconds = "30",
    [string]$cleanupPreviousFolders = "false",
    [string]$logPath = "../logs"
)

if
(-not (Get-Command -name "java" -CommandType Application -errorAction SilentlyContinue))
{
    Write-Error "Java not installed"
    break
}

$argList = @("install",
            "BitBucketRunner",
            "--Install=D:\bb\bin\prunsrv.exe",
            "--Startup=auto",
            "--Classpath=runner.jar",
            "--StartClass=com.atlassian.pipelines.runner.core.ApplicationImpl",
            "--StartMethod=main",
            "--StopClass=com.atlassian.pipelines.runner.core.ApplicationImpl",
            "--StopMethod=main",
            '--DisplayName="Bitbucket Runner"',
            '--Description="Bitbucket Runner Service"',
            "--StartMode=jvm",
            "--StopMode=jvm",
            "--Jvm=auto",
            "--ServiceUser=$serviceUser",
            "--ServicePassword=$servicePassword",
            "++JvmOptions=-Dbitbucket.pipelines.runner.account.uuid=$accountUuid",
            "++JvmOptions=-Dbitbucket.pipelines.runner.repository.uuid=$repositoryUuid",
            "++JvmOptions=-Dbitbucket.pipelines.runner.uuid=$runnerUuid",
            "++JvmOptions=-Dbitbucket.pipelines.runner.environment=$runnerEnvironment",
            "++JvmOptions=-Dbitbucket.pipelines.runner.oauth.client.id=$OAuthClientId",
            "++JvmOptions=-Dbitbucket.pipelines.runner.oauth.client.secret=$OAuthClientSecret",
            "++JvmOptions=-Dbitbucket.pipelines.runner.directory.working=$workingDirectory",
            "++JvmOptions=-Dbitbucket.pipelines.runner.runtime=windows-powershell",
            "++JvmOptions=-Dbitbucket.pipelines.runner.scheduled.state.update.initial.delay.seconds=$scheduledStateUpdateInitialDelaySeconds",
            "++JvmOptions=-Dbitbucket.pipelines.runner.scheduled.state.update.period.seconds=$scheduledStateUpdatePeriodSeconds",
            "++JvmOptions=-Dbitbucket.pipelines.runner.cleanup.previous.folders=$cleanupPreviousFolders"
            "++JvmOptions=-Dfile.encoding=UTF-8",
            "++JvmOptions=-Dsun.jnu.encoding=UTF-8",
            "--JvmMs=256",
            "--JvmMx=1024",
            "--JvmSs=4000",
            "--LogPath=$logPath",
            "--LogPrefix=bitbucket-agent",
            "--StdOutput=$logPath\stdout.log",
            "--StdError=$logPath\stderr.log")

$params
= @{
    FilePath = "prunsrv"
    ArgumentList = $argList
}

$p = Start-Process @params -NoNewWindow -Wait

Create uninstall.ps1 in D:\bb\bin
$argList = @("delete",
            "BitBucketRunner")

$params = @{
    FilePath = "prunsrv"
    ArgumentList = $argList
}

$p = Start-Process @params -NoNewWindow -Wait

CD into D:\bb\bin and run
.\install.ps1 -accountUuid '{*****}' -runnerUuid '{*****}' -OAuthClientId ***** -OAuthClientSecret ***** -workingDirectory '..\temp' -serviceUser DOMAIN\user -servicePassword ***

I can't get my service to start after following this installation procedure. procmon requires an Oracle JDK properly installed in the registry but Bitbucket runner only works with OpenJDK. How did you do it? Thanks.

I used the Eclipse Adoptium Java version and then

1. Added this JAVA_HOME to environment variables: 

C:\Program Files\Eclipse Adoptium\jdk-11.0.16.101-hotspot

 

2. Added to PATH: 

C:\Program Files\Eclipse Adoptium\jdk-11.0.16.101-hotspot\bin

Like sebastien_ezfocus likes this

Thank you very much!

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 11, 2022

Hi @fernando_arias ,

welcome to the Atlassian community!

You need to install a service. Please take a look to the following article  https://confluence.atlassian.com/bitbucketserver/start-and-stop-bitbucket-776640144.html

Hope this helps,

Fabio

Thanks, Fabio

Looks like the answer is for running Bitbucket as a service, but I'm talking about a Bitbucket Windows runner.

Suggest an answer

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

Atlassian Community Events