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 which 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. Then back 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
  7. Make the init script executable:

    chmod a+x /etc/init.d/bamboo
  8. 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
  9. 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 Sep 7, 2016

Was this helpful?

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