Running Bitbucket Server as a Linux service

This page describes how to run Bitbucket Server as a Linux service, and only applies if you are manually installing or upgrading Bitbucket Server from an archive file. See the page Install Bitbucket Server from an archive file for more details. 

Bitbucket Server assumes that the external database is available when it starts; these approaches do not support service dependencies, and the startup scripts will not wait for the external database to become available.

For production use on a Linux server, Bitbucket Server should be configured to run as a Linux service, that is, as a daemon process. This has the following advantages:

  • Bitbucket Server can be automatically restarted when the operating system restarts.
  • Bitbucket Server can be automatically restarted if it stops for some reason.
  • Bitbucket Server is less likely to be accidentally shut down, as can happen if the terminal Bitbucket Server was manually started in is closed.
  • Logs from the Bitbucket Server JVM can be properly managed by the service.

System administration tasks are not supported by Atlassian. These instructions are only provided as a guide and may not be up to date with the latest version of your operating system.


Using the Java Service Wrapper

Bitbucket Server can be run as a service on Linux using the Java Service Wrapper. The Service Wrapper is known to work with Debian, Ubuntu, and Red Hat.

The Service Wrapper provides the following benefits:

  • Allows Bitbucket Server, which is a Java application, to be run as a service.
  • No need for a user to be logged on to the system at all times, or for a command prompt to be open and running on the desktop to be able to run Bitbucket Server.
  • The ability to run Bitbucket Server in the background as a service, for improved convenience, system performance and security.
  • Bitbucket Server is launched automatically on system startup and does not require that a user be logged in. 
  • Users are not able to stop, start, or otherwise tamper with Bitbucket Server unless they are an administrator.
  • Can provide advanced failover, error recovery, and analysis features to make sure that Bitbucket Server has the maximum possible uptime.

Please see for wrapper installation and configuration instructions.

The service wrapper supports the standard commands for SysV init scripts, so it should work if you just create a symlink to it from /etc/init.d.

Using an init.d script

The usual way on Linux to ensure that a process restarts at system restart is to use an init.d script. This approach does not restart Bitbucket Server if it stops by itself.

  1. Stop Bitbucket Server.
  2. Create a bitbucket user, set the permissions to that user, create a home directory for Bitbucket Server and create a symlink to make upgrades easier:

    $> curl -OL
    $> tar xz -C /opt -f atlassian-bitbucket-X.Y.Z.tar.gz
    $> ln -s /opt/atlassian-bitbucket-X.Y.Z /opt/atlassian-bitbucket-latest
    # Create a home directory
    $> mkdir /opt/bitbucket-home
    # ! Update permissions and ownership accordingly

    (Be sure to replace X.Y.Z in the above commands with the version number of Bitbucket Server.)

  3. Create the startup script in /etc/init.d/bitbucket with the following contents (Ensure the script is executable by running chmod 755 bitbucket):

    #! /bin/sh
    # Provides:          bitbucket
    # Required-Start:    $remote_fs $syslog
    # Required-Stop:     $remote_fs $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Initscript for Atlassian Bitbucket Server
    # Description:  Automatically start Atlassian Bitbucket Server when the system starts up.
    #               Provide commands for manually starting and stopping Bitbucket Server.
    # Adapt the following lines to your configuration
    # RUNUSER: The user to run Bitbucket Server as.
    # BITBUCKET_INSTALLDIR: The path to the Bitbucket Server installation directory
    # BITBUCKET_HOME: Path to the Bitbucket home directory
    # ==================================================================================
    # ==================================================================================
    # ==================================================================================
    # PATH should only include /usr/* if it runs after the script
    DESC="Atlassian Bitbucket Server"
    # Read configuration variable file if it is present
    [ -r /etc/default/$NAME ] && . /etc/default/$NAME
    # Define LSB log_* functions.
    # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
    . /lib/lsb/init-functions
    run_with_home() {
        if [ "$RUNUSER" != "$USER" ]; then
    # Function that starts the daemon/service
    # Function that stops the daemon/service
        if [ -e $PIDFILE ]; then
          log_failure_msg "$NAME is not running."
    case "$1" in
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        case "$?" in
            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
            2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        case "$?" in
            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
            2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
           if [ ! -e $PIDFILE ]; then
             log_failure_msg "$NAME is not running."
             return 1
           status_of_proc -p $PIDFILE "" $NAME && exit 0 || exit $?
        # If the "reload" option is implemented then remove the
        # 'force-reload' alias
        log_daemon_msg "Restarting $DESC" "$NAME"
        case "$?" in
            case "$?" in
                0) log_end_msg 0 ;;
                1) log_end_msg 1 ;; # Old process is still running
                *) log_end_msg 1 ;; # Failed to start
            # Failed to stop
            log_end_msg 1
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
        exit 3

Running on system boot

  1. To start on system boot, add the script to the start up process.
    For Ubuntu (and other Debian derivatives) use:

    update-rc.d bitbucket defaults

    For RHEL (and derivates) use:

    chkconfig --add bitbucket --level 0356

    Note: You may have to install the redhat-lsb package on RHEL (or derivatives) to provide the LSB functions used in the script.

  2. Verify that the Bitbucket Server service comes back up after restarting the machine.


Using a systemd unit file

Thanks to Patrick Nelson for calling out this approach, which he set up for a Fedora system. It also works on other distributions that use systemd as the init system. This approach does not restart Bitbucket Server if it stops by itself.

  1. Create a bitbucket.service file in your /etc/systemd/system/ directory with the following lines:

    Description=Atlassian Bitbucket Server Service

    The value for User should be adjusted to match the user that Bitbucket Server runs as. ExecStart and ExecStop should be adjusted to match the path to your <Bitbucket Server installation directory>.

  2. Enable the service to start at boot time by running the following in a terminal:

    systemctl enable bitbucket.service
  3. Stop Bitbucket Server, then restart the system, to check that Bitbucket Server starts as expected.
  4. Use the following commands to manage the service:
    Disable the service:
    systemctl disable bitbucket.service
    Check that the service is set to start at boot time:
    if [ -f /etc/systemd/system/*.wants/bitbucket.service ]; then echo "On"; else echo "Off"; fi
    Manually start and stop the service: 
    systemctl start bitbucket
    systemctl stop bitbucket
    Check the status of Bitbucket Server:
    systemctl status bitbucket
Last modified on Feb 2, 2021

Was this helpful?

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