Running Bitbucket Server as a Windows service

This page only applies...

... if you are manually installing or upgrading Bitbucket Server from an archive file .

If you're using the installer...

... you should read the Bitbucket Server Getting started page instead.

We recommend that you use the Bitbucket Server installer to install Bitbucket Server as a service on Windows. It installs Bitbucket Server as a service and creates items in the Windows 'Start' menu for starting and stopping Bitbucket Server – see Getting started

The information on this page only applies if you are manually installing or upgrading Bitbucket Server from an archive file. See  Install Bitbucket Server from an archive file .

For long-term use on a Windows server, Bitbucket Server should be configured to run as a Windows service. This has the following advantages:

  • Bitbucket Server will be automatically restarted when the operating system restarts. 
  • Bitbucket Server is less likely to be accidentally shut down, as can happen if the console window Bitbucket Server was manually started in is closed.
  • Bitbucket Server logs are properly managed by the Windows service.

 

System administration tasks are not supported by Atlassian. These instructions are only provided as a guide.

 

Prerequisites

  • If you are using a 64-bit version of Windows, first ensure that Bitbucket Server uses a 64-bit JVM (check by running java -version in a Command Prompt, and ensure that the JAVA_HOME system environment variable points to the 64-bit JVM), and then replace the 32-bit Tomcat binaries with their 64-bit counterparts  in the <Bitbucket Server installation directory>/bin directory:

    cd <BITBUCKET-INST/bin>
    rename tomcat8.exe tomcat8.exe.x86
    rename tcnative-1.dll tcnative-1.dll.x86
    rename tomcat8.exe.x64 tomcat8.exe
    rename tcnative-1.dll.x64 tcnative-1.dll
  • On any Windows operating system with User Account Control (UAC) such as Windows Vista or Windows 7, simply logging in to Windows with an Administrator account will not be sufficient to execute the script in the procedure below. You must either disable UAC or run 'cmd.exe' as an administrator (e.g. by right-clicking on 'cmd.exe' and choosing Run as administrator).
  • Ensure the JAVA_HOME variable is set to the root of your Java platform's installation directory.
    Note: Your JAVA_HOME cannot contain spaces, so the default Java installation directory of C:\Program Files\Java won't work.
  • Bitbucket Server should be run from a local dedicated user account that does not have admin privileges and that has read, write and execute access to the Bitbucket home directory and the <Bitbucket Server installation directory>. See Git push operations extremely slow on Windows.
  • When you run Bitbucket Server as a Windows service, all settings in setenv.bat are ignored. Ensure that you have set BITBUCKET_HOME as a system environment variable, before running the service.bat script.
  • If you upgraded Bitbucket Server from version 1.x to 2.x and Bitbucket Server stopped running as a service you will need to reinstall the service according to instructions in the Bitbucket Server upgrade guide.

Set up Bitbucket Server as a Windows service

The information in this section only applies if you are manually installing Bitbucket Server as a Windows service. Alternatively, you can use the Bitbucket Server installer for Windows to install Bitbucket Server as a service – see Running the Bitbucket Server installer .

To run Bitbucket Server as a Windows service:

  1. Stop Bitbucket Server.
  2. Create a system environment variable with BITBUCKET_HOME as the Variable name and the absolute path to your Bitbucket Server home directory as the Variable value. Don't use a trailing backslash. Note that the Bitbucket home directory should not be located inside the <Bitbucket Server installation directory>. You must do this step before running the service.bat script in Step 5 below.
  3. Open a Command Prompt (as an Administrator – see the 'Prerequisites' section above).
  4. Change directory to the Bitbucket Server installation directory and then into the bin subdirectory. If a directory in the path has spaces (e.g. C:\Program Files\..), use its eight-character equivalent (e.g. C:\Progra~1\..).
  5. Run the following commands:

    > service.bat install
    > tomcat8 //US//AtlassianBitbucket --Startup auto

    This will create a service with the name "AtlassianBitbucket" and a display name of "Atlassian Bitbucket Server".  If you would like to customize the name you can instead run:

    > service.bat install MyName
    > tomcat8 //US//MyName --Startup auto

    This will create the service as "MyName" with a display name of "Atlassian Bitbucket Server MyName".

  6. Run the following command to increase the amount of memory that Bitbucket Server can use (the default is 768 Mb):

    > tomcat8 //US//service_name --JvmMx 1024
  7. Verify that the Bitbucket Server service comes back up after restarting the machine.

Here is an example:

C:\Program Files (x86)\atlassian-bitbucket-2.0.0\bin>service.bat install
Installing the service 'AtlassianBitbucket Server' ...
Using CATALINA_HOME:    "C:\Program Files (x86)\atlassian-bitbucket-2.0.0"
Using CATALINA_BASE:    "C:\Program Files (x86)\atlassian-bitbucket-2.0.0"
Using JAVA_HOME:        "C:\Java\jre6"
Using JVM:              "auto"
The service 'AtlassianBitbucket Server' has been installed.
C:\Program Files (x86)\atlassian-bitbucket-2.0.0\bin>tomcat8.exe //US//AtlassianBitbucket Server --Startup auto
C:\Program Files (x86)\atlassian-bitbucket-2.0.0\bin>tomcat8.exe //US//AtlassianBitbucket Server --JvmMx 1024
 
C:\Program Files (x86)\atlassian-bitbucket-2.0.0\bin>net start AtlassianBitbucket Server
The Atlassian Bitbucket Server service is starting.
The Atlassian Bitbucket Server service was started successfully.

Troubleshooting

  • If your service fails to start with "code 4", make sure you ran service.bat install in a Command Prompt running as an Administrator.
Last modified on Mar 15, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.