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 /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 -e
    # bamboo startup script
    #chkconfig: 2345 80 05
    #description: bamboo
    
    # 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
    # Location of Java JDK
    export JAVA_HOME=/usr/lib/jvm/java-6-sun
    
    case "$1" in
      # Start command
      start)
        echo "Starting $APP"
        /bin/su -m $USER -c "cd $BASE/logs && $BASE/bin/startup.sh &> /dev/null"
        ;;
      # Stop command
      stop)
        echo "Stopping $APP"
        /bin/su -m $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. 初期化スクリプトを実行可能にします:

    chmod \+x /etc/init.d/bamboo
  8. シンボリックリンクをランレベルのディレクトリに配置し、このスクリプトの開始と停止を自動的に行えるようにします。 

    1. Debian ベースのシステムの場合:

      update-rc.d bamboo defaults

      上記のコマンドを実行する事で、シンボリックリンクをランレベルのディレクトリに配置します:

      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. RedHat ベースのシステムの場合:

      init.d スクリプトに chkconfig 設定が含まれています

      sudo /sbin/chkconfig --add bamboo
  9. スクリプトが正しい順序で実行されるようにします (特にデータベースの起動スクリプトの後に実行されるように)。
  • ラベルなし

15 Comments

  1. Martin

    # Location of Java JDK
    export JAVA_HOME=/usr/lib/jvm/java-6-sun

     

    I would suggest not to export JAVA_HOME in the init script by default unless the JDK path found by setclasspath.sh doesn't match the preferred one.

  2. Ronald Bolante

    I don't see the point of going to the logs directory ($BASE/logs) before executing the init script in this line:

    /bin/su -m $USER -c "cd $BASE/logs && $BASE/bin/startup.sh &> /dev/null"

    Is it to make sure that the logs directory exist because of the '&&' ?  To think that this directory is created by default.

    Anyway, no biggie just a thought. (smile)

  3. Anonymous

    If service bamboo start is ran while bamboo is running it creates a new bamboo process.

    1. ArmenA

      Running more than one Bamboo instances on the same machine is allowed. That's why Bamboo doesn't care if there is already another Bamboo instance running. However, if you are using the same port for both of them, there will be conflicts.

  4. Wahid Atif

    Hi Nathan,

    your init script is not LSB conform. That why Debian users will become this warning:

    insserv: warning: script 'bamboo' missing LSB tags and overrides

     

    Just replace that block:

     

    #!/bin/sh -e
    # bamboo startup script
    #chkconfig: 2345 80 05
    #description: bamboo

     

    With:

     

    #!/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
    ######################################

     

    Tested on Debian Wheezy.

  5. Wahid Atif

    Here is my version with "status" command:

    #!/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/bamboo
    tomcat_pid() {
       echo `ps aux | grep "Dcatalina.base=/opt/bamboo" | grep -v grep | awk '{ print $2 }'`
    }
    case "$1" in
      # Start command
      start)
        echo "Starting $APP"
        /bin/su - $USER -c "export JAVA_HOME=/opt/jdk && cd $BASE/logs && $BASE/bin/startup.sh &> /dev/null"
        ;;
      # Stop command
      stop)
        echo "Stopping $APP"
        /bin/su - $USER -c "export JAVA_HOME=/opt/jdk && $BASE/bin/shutdown.sh &> /dev/null"
        echo "$APP stopped successfully"
        ;;
       # Restart command
       restart)
            $0 stop
            sleep 5
            $0 start
            ;;
       status)
            pid=$(tomcat_pid)
            if [ -n "$pid" ]
            then
                    echo "Your Bamboo Instance is running with pid: $pid"
            else
    				echo "Your Bamboo Instance is not running"
            fi
            ;;
      *)
        echo "Usage: /etc/init.d/$APP {start|restart|stop|status}"
        exit 1
        ;;
    esac
    exit 0
    1. Stephen Moretti

      Nice idea to add the status command. Unfortunately there are two problems.  

      The first is that this code is incomplete and so will error. 

      The second is that using catalina bootstrap as the trigger for PID is flawed.  We run JIRA, Crowd and Confluence on one server, so this command returns a number of PIDs and doesn't determine directly whether bamboo is running. 

      If I get a chance I'll try to come up with a working version of this script.

      1. Wahid Atif

        Hi Stephen,

        I've just edited the script code into my current working version, it was a copy/paste typo.

        For your second note, I had also to change the grep expression into

        ps aux | grep "Dcatalina.base=/path/to/bamboo/install/dir"

        to get the unique PID of the running bamboo instance.

  6. Daniel Hopper

    Why would the -m (preserve environment) be on this startup script.  That seems like that will cause issues if this script is run as root and it generally is as it will then have all the root user environment instead of the bamboo user.

    1. Gary Kennedy

      The -m argument indeed causes problems. The one we are getting at the moment is git is looking in the $HOME folder for config and of course can't access it because it is running as a different user. ($HOME is still pointing to /root because of this switch)

      We are doing some other bamboo user changeover stuff at the moment, but we'll be removing that switch when we next use the service script. I'll let you know how it goes.

      1. Daniel Hopper

        Exactly, I removed the -m flag and instead use /bin/su - $USER, that way the proper users environment is used instead of whoever is running the command

        1. Gary Kennedy

          I think the only use for the flag is to keep the JAVA_HOME setting.

          In which case you can set this up in the user profile, which also allows you to setup other tool config easily - seems better to me (smile)

          1. Daniel Hopper

            So to be completely clear this is actually what I use

            /bin/su - $USER -c "export JAVA_HOME=/usr/java/latest/ && cd $BASE/logs && $BASE/bin/startup.sh &> /dev/null"

            Thus setting the JAVA_HOME value for the particular user.  Which could as well be accomplished in their particular shell profile as you mentioned (i.e. .bash_profile) but I don't particular like to rely on that myself and prefer to have the startup script be pretty deterministic in itself.

            1. Wahid Atif

              You are abolutely right! I just got a failed Bamboo build because Bamboo tried to look for Maven settings.xml on /root/.m2/ instead of /home/<BAMBOO-USER>/.m2/! Here is the build output:

               

              command	20-Dec-2013 10:33:19	Beginning to execute external process for build 'Main Build (TRUNK) - Deployment #13 (MAIN-DEP-13)'\n ... running command line: \n/opt/jdk/bin/java -cp /opt/apache-maven-3.0.5/boot/plexus-classworlds-2.4.jar -Dclassworlds.conf=/opt/atlassian/bamboo/atlassian-bamboo-5.3/temp/artifactoryM22579890451218039914conf -DbuildInfoConfig.propertiesFile=/opt/atlassian/bamboo/atlassian-bamboo-5.3/temp/buildInfo6443305367254087071properties -Xmx256m -Xms128m -Dmaven.home=/opt/apache-maven-3.0.5 org.codehaus.plexus.classworlds.launcher.Launcher --batch-mode release:prepare -DdevelopmentVersion=3.13-SNAPSHOT -DreleaseVersion=3.12 -Dusername=bamboo -Dpassword=*****\n ... in: /opt/bamboo-home/xml-data/build-dir/MAIN-DEP-13\n ... using extra environment variables: \nTERM=xterm\nJAVA_HOME=/opt/jdk\nSHLVL=1\nXFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt\nSUDO_UID=1000\nMAIL=/var/mail/root\nPWD=/opt/bamboo/logs\nJAVA_OPTS=-XX:MaxPermSize=256m -Xms256m -Xmx384m    \nLOGNAME=root\nbamboo_releaseVersion=3.12\nSUDO_USER=bamboo\n_=/opt/bamboo/bin/startup.sh\nNLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat\nOLDPWD=/opt/artifactory-3.1.0/webapps\nbamboo_snapshotVersion=3.13-SNAPSHOT\nSHELL=/bin/bash\nLANGUAGE=en_US:en\nSUDO_GID=1000\nJAVA_PERMGEN_SUPPORTED=true\nUSER=bamboo\nHOME=/root\nSUDO_COMMAND=/etc/init.d/bamboo start\nLS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:\nUSERNAME=root\nLANG=en_US.UTF-8\nPATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games\n

              Found the following extra environment variables:

              • MAIL=/var/mail/root
              • HOME=/root
              • LOGNAME=root
              • USERNAME=root

              Thank you for the helpful hint!

  7. ArmenA

    Regarding the -m option, we decided to leave it as it is now to avoid any possible misbehavior that can happen in some specific environments. If anybody is confident of changing it in his own instance and being responsible for maintenance and troubleshooting, feel free to do so.

    Armen