Running Bamboo as a Linux service

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

Linux system administration is outside the scope of Atlassian support. This page is provided for your information only.

On Linux/Solaris, the best practice is to install, configure and run each service (including Bamboo) as a dedicated user with only the permissions they require.

To install, configure and get Bamboo to start automatically on Linux/Solaris:

  1. Create a bamboo user account that will be used to run Bamboo. For example, enter the following at a Linux console:

    sudo useradd --create-home -c "Bamboo role account" bamboo
  2. Create a directory into which Bamboo will be installed. For example:

    sudo mkdir -p /opt/atlassian/bamboo
    sudo chown bamboo: /opt/atlassian/bamboo
  3. Log in as the bamboo user to install Bamboo:

    sudo su - bamboo
  4. You need to extract Bamboo:

    cd /opt/atlassian/bamboo
    tar zxvf /tmp/atlassian-bamboo-X.Y.tar.gz
    ln -s atlassian-bamboo-X.Y/ current
  5. Edit current/atlassian-bamboo/WEB-INF/classes/bamboo-init.properties and set bamboo.home=/var/atlassian/application-data/bamboo (or any other directory of your choice, but not the same as Bamboo's installation directory)
  6. Proceed with the service configuration. There are two options included below for creating the service configuration, which one you will use will depend on your Linux distribution:


Systemd Service Configuration

Suitable for modern distributions such as:

  • Ubuntu 15
  • CentOS 7
  • RHEL 7

For anything older see the SysV Init Script section below.

Systemd will ignore environment variable definitions placed in /etc/environment as well as other traditional environment variable definitions from Sys-V init. If one needs to define environment variables when running Bamboo as a systemd unit then the variable definitions need to be placed in the unit file.

The examples below are designed for Bamboo Server. If you want to automate the Remote Agent service, simply replace ExecStart/ExecStop instructions with:

ExecStart=<bamboo-agent-home>/bin/bamboo-agent.sh start sysd
ExecStop=<bamboo-agent-home>/bin/bamboo-agent.sh stop sysd

Environment=CATALINA_PID and PIDFile properties can be removed as the Remote Agent startup is controlled by a service wrapper.

  1. Create a bamboo.service file in your /etc/systemd/system directory

    [Unit]
    Description=Atlassian Bamboo
    After=syslog.target network.target
    
    [Service]
    Type=forking
    User=<bamboo-user>
    Environment=CATALINA_PID=<bamboo-install>/bin/Catalina.pid
    PIDFile=<bamboo-install>/bin/Catalina.pid
    ExecStart=<bamboo-install>/bin/start-bamboo.sh
    ExecStop=<bamboo-install>/bin/stop-bamboo.sh
    SuccessExitStatus=143
    
    [Install]
    WantedBy=multi-user.target

    The values for <bamboo-user> and <bamboo-install> should be replaced with your Bamboo user and the path to your Bamboo Install directory, respectively. CATALINA_PID and PIDFile are also declared, this way systemd knows which java process to monitor.

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

    systemctl enable bamboo.service
  3. Stop Bamboo using the provided Bamboo stop script (<bamboo-install>/bin/stop-bamboo.sh) and restart your system to check that Bamboo starts as expected
  4. Use the following commands to manage the service:

    Disable the service:

    systemctl disable bamboo.service


    Check that the service is set to start at boot time:

    if [ -f /etc/systemd/system/*.wants/bamboo.service ]; then echo "On"; else echo "Off"; fi


    Manually start and stop the service:

    systemctl start bamboo
    systemctl stop bamboo


    Check the status of Bamboo:

    systemctl status bamboo
SysV Init Script

  1. As root, create the file /etc/init.d/bamboo (code shown below), which will be responsible for starting up bamboo after a reboot (or when manually invoked).

    #!/bin/sh
    set -e
    ### BEGIN INIT INFO
    # Provides: bamboo
    # Required-Start: $local_fs $remote_fs $network $time
    # Required-Stop: $local_fs $remote_fs $network $time
    # Should-Start: $syslog
    # Should-Stop: $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Atlassian Bamboo Server
    ### END INIT INFO
    # INIT Script
    ######################################
    
    # Define some variables
    # Name of app ( bamboo, Confluence, etc )
    APP=bamboo
    # Name of the user to run as
    USER=bamboo
    # Location of application's bin directory
    BASE=/opt/atlassian/bamboo/current
    
    case "$1" in
      # Start command
      start)
        echo "Starting $APP"
        /bin/su - $USER -c "export BAMBOO_HOME=${BAMBOO_HOME}; $BASE/bin/startup.sh &> /dev/null"
        ;;
      # Stop command
      stop)
        echo "Stopping $APP"
        /bin/su - $USER -c "$BASE/bin/shutdown.sh &> /dev/null"
        echo "$APP stopped successfully"
        ;;
       # Restart command
       restart)
            $0 stop
            sleep 5
            $0 start
            ;;
      *)
        echo "Usage: /etc/init.d/$APP {start|restart|stop}"
        exit 1
        ;;
    esac
    
    exit 0
  2. Make the init script executable:

    chmod a+x /etc/init.d/bamboo
  3. Place symlinks in the run-level directories to start and stop this script automatically. 

    1. For Debian-based systems:

      update-rc.d bamboo defaults

      The following commands will be executed to place symlinks in the run-level directories:

      Adding system startup for /etc/init.d/bamboo ...
         /etc/rc0.d/K20bamboo -> ../init.d/bamboo
         /etc/rc1.d/K20bamboo -> ../init.d/bamboo
         /etc/rc6.d/K20bamboo -> ../init.d/bamboo
         /etc/rc2.d/S20bamboo -> ../init.d/bamboo
         /etc/rc3.d/S20bamboo -> ../init.d/bamboo
         /etc/rc4.d/S20bamboo -> ../init.d/bamboo
         /etc/rc5.d/S20bamboo -> ../init.d/bamboo
    2. For RedHat-based systems:

      tip/resting Created with Sketch.

      the init.d script contains chkconfig settings

      sudo /sbin/chkconfig --add bamboo
  4. Ensure the script is executed in the correct order, in particular after the database startup script.

Note: If starting your new bamboo service fails immediately with an error, it may be that your /etc/init.d/bamboo script has had carriage return characters introduced into it. You can confirm this by running: 

cat -v /etc/init.d/bamboo

If there are carriage return characters in your /etc/init.d/bamboo script, they will appear as ^M in the output: 

#!/bin/sh^M
set -e^M
### BEGIN INIT INFO^M
# Provides: bamboo^M
# Required-Start: $local_fs $remote_fs $network $time^M
# Required-Stop: $local_fs $remote_fs $network $time^M
# Should-Start: $syslog^M
# Should-Stop: $syslog^M

You can remove carriage return characters from /etc/init.d/bamboo with the following command: 

sed -i -e 's/\r//g' /etc/init.d/bamboo
Retry starting the service after making this change.
Last modified on Mar 15, 2024

Was this helpful?

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