Dec 02, 2014 Tag: Linux

Linux Scripts for Easy YouTrack Installation

Credit:

Much of this post is a reproduction from JetBrains article “Linux Scripts for Easy YouTrack Installation”. The intention is to keep that recipe at a “warm and safe place” here and to leave amendments and extras I found necessary when installing YouTrack on Ubuntu Trusty Tahr 14.04 LTS.

Note: This is an example of how to install an application as Linux service as well!

Compare with Ubuntu: About “Writing Jobs”

Updated on Feb 12, 2015

Install Java

YouTrack 6.x requires Oracle Java 7 or 8. I followed a recipe from a webpage How To Install Oracle Java 7 In Debian Via Repository. Instead of ‘ubuntu precise’ it’s ‘trusty’ we’re dealing with. So these are the important steps:

su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
apt-get update
apt-get install oracle-java8-installer
exit

Afterwards I found the Oracle Java 8 installation at /usr/lib/jvm/java-8-oracle. So that’s what goes into the ‘Java home’ variable later: export JAVA_HOME=/usr/lib/jvm/java-8-oracle.

Install YouTrack

Many thanks to Alexey Efimov for sharing the scripts provided in this guide.

To quickly install YouTrack from .jar distribution under Linux, perform the following steps as root user:

  1. Add a user:

    adduser youtrack --disabled-password
    
  2. Create a directory:

    mkdir -p /usr/local/youtrack
    chown youtrack.youtrack /usr/local/youtrack
    
  3. Create script init.d:

    vim /etc/init.d/youtrack
    
  4. Paste the following code into init.d:

    #! /bin/sh
    
    ### BEGIN INIT INFO
    # Provides:          youtrack
    # Required-Start:    $local_fs $remote_fs
    # Required-Stop:     $local_fs $remote_fs
    # Default-Start:     2 3 4 5
    # Default-Stop:      S 0 1 6
    # Short-Description: initscript for youtrack
    # Description:       initscript for youtrack
    ### END INIT INFO
    
    export HOME=/home/youtrack
    
    set -e
    
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    NAME=youtrack
    SCRIPT=/usr/local/$NAME/$NAME.sh
    
    d_start() {
        su youtrack -l -c "$SCRIPT start"
    }
    
    d_stop() {
        su youtrack -l -c "$SCRIPT stop"
    }
    
    case "$1" in
      start)
        echo "Starting $NAME..."
        d_start
        ;;
        stop)
        echo "Stopping $NAME..."
        d_stop
        ;;
      restart|force-reload)
        echo "Restarting $NAME..."
        d_stop
        d_start
        ;;
      *)
        echo "Usage: sudo /etc/init.d/youtrack {start|stop|restart}" >&2
        exit 1
        ;;
    esac
    
    exit 0
    
  5. Save the script and grant it exec privileges:

    chmod +x /etc/init.d/youtrack
    
  6. Install init.d:

    /usr/sbin/update-rc.d youtrack defaults
    
  7. Create a run script:

    vim /usr/local/youtrack/youtrack.sh
    
  8. Paste the following code into youtrack.sh. Modify JAVA_HOME variable to correctly reference your Java installation home directory (make sure to have JDK installed beforehand):

    #! /bin/sh
    
    export HOME=/home/youtrack
    export JAVA_HOME=/usr/local/java6  # Modify this line!
    export JAVA_HOME=/usr/lib/jvm/java-8-oracle # ubuntu 14.04 LTS, # mb, 2014-12-02
    
    NAME=youtrack
    PORT=8112
    USR=/usr/local/$NAME
    JAR=$USR/`ls -Lt $USR/*.jar | grep -o "$NAME-[^/]*.jar" | head -1`
    LOG=$USR/$NAME-$PORT.log
    LOG=/dev/null  # mb, 2014-12-02. I don't want to log to my SSD
    
    PID=$USR/$NAME-$PORT.pid
    
    d_start() {
        if [ -f $PID ]; then
            PID_VALUE=`cat $PID`
            if [ ! -z "$PID_VALUE" ]; then
                PID_VALUE=`ps ax | grep $PID_VALUE | grep -v grep | awk '{print $1}'`
                if [ ! -z "$PID_VALUE" ]; then
                    exit 1;
                fi
            fi
        fi
    
        PREV_DIR=`pwd`
        cd $USR
    
    
        # This 'exec' does not work for Youtrack 6.x on Ubuntu 14.04 LTS
        # exec $JAVA_HOME/bin/java -Xmx512m -jar $JAR $PORT >> $LOG 2>&1 &
    
        # MaxPermSize must be >= 256m, recommended -Xmx >= 1g # mb, 2014-12-02
        exec $JAVA_HOME/bin/java -XX:MaxPermSize=1024m  -Xmx1g -jar $JAR $PORT >> $LOG 2>&1 &
    
        echo $! > $PID
        cd $PREV_DIR
    }
    
    d_stop() {
        if [ -f $PID ]; then
            PID_VALUE=`cat $PID`
            if [ ! -z "$PID_VALUE" ]; then
                PID_VALUE=`ps ax | grep $PID_VALUE | grep -v grep | awk '{print $1}'`
                if [ ! -z "$PID_VALUE" ]; then
                    kill $PID_VALUE
                    WAIT_TIME=0
                    while [ `ps ax | grep $PID_VALUE | grep -v grep | wc -l` -ne 0 -a "$WAIT_TIME" -lt 2 ]
                    do
                        sleep 1
                        WAIT_TIME=$(expr $WAIT_TIME + 1)
                    done
                    if [ `ps ax | grep $PID_VALUE | grep -v grep | wc -l` -ne 0 ]; then
                        WAIT_TIME=0
                        while [ `ps ax | grep $PID_VALUE | grep -v grep | wc -l` -ne 0 -a "$WAIT_TIME" -lt 15 ]
                        do
                            sleep 1
                            WAIT_TIME=$(expr $WAIT_TIME + 1)
                        done
                        echo
                    fi
                    if [ `ps ax | grep $PID_VALUE | grep -v grep | wc -l` -ne 0 ]; then
                        kill -9 $PID_VALUE
                    fi
               fi
            fi
            rm -f $PID
        fi
    }
    
    case "$1" in
        start)
            d_start
        ;;
        stop)
            d_stop
        ;;
        *)
            echo "Usage: $0 {start|stop|restart}" >&2
            exit 1
        ;;
    esac
    
    exit 0
    
  9. Save youtrack.sh and grant it exec privileges:

    chmod +x /usr/local/youtrack/youtrack.sh
    
  10. Download the latest YouTrack JAR file (make sure to change <version> accordingly):

    sudo su youtrack -l -c "cd /usr/local/youtrack && wget http://download.jetbrains.com/charisma/youtrack-<version>.jar"
    

or, better, follow this method to download:

  1. (improved) Download the latest YouTrack JAR file (make sure to change <version> accordingly). Look up the current version at the jetbrains.com Website (Youtrack,Try): You should see something like this:

    RESOLVEME://files/001.png

    This means it’s YouTrack file ‘youtrack-6.0.12223.jar’ that you can download.

    Download the YouTrack JAR file:

    theFile=youtrack-6.0.12223.jar
    sudo su youtrack -l
    cd /usr/local/youtrack
    wget http://download.jetbrains.com/charisma/${theFile} -O ${theFile}
    
  2. Run YouTrack:

    sudo /etc/init.d/youtrack restart
    

    YouTrack will run on port 8112 like http://localhost:8112

Note: For completeness I keep the recipe to install lighttpd here but didn’t test the following steps concerning lighttpd.

  1. Install lighttpd1.5 server:

    vim /etc/lighttpd/conf-available/20-youtrack.conf
    
  2. To configure proxy, paste the following code:

    server.modules  += ( "mod_proxy_core" )
    server.modules  += ( "mod_proxy_backend_http" )
    
    #$HTTP["host"] =~ "^youtrack\." {
      proxy-core.protocol = "http"
      proxy-core.backends = ( "localhost:8112" )
      proxy-core.max-pool-size = 16
    #}
    

    Uncomment commented lines if you have virtual hosts for YouTrack on a multiple-site host.

  3. Add a symbolic link:

    ln -s /etc/lighttpd/conf-available/20-youtrack.conf /etc/lighttpd/conf-enabled/20-youtrack.conf
    
  4. Restart lighttpd:

    /etc/init.d/lighttpd1.5 restart
    

You can now access YouTrack on port 80 via HTTP.

Upgrade YouTrack

  1. To upgrade YouTrack go to the Jetbrains -> Youtrack -> Try website and find out about the exact build number. You’ll see something like this:

    RESOLVEME://files/001.png

    This means it’s YouTrack file ‘youtrack-6.0.12223.jar’

    Download the YouTrack JAR file:

    theFile=youtrack-6.0.12223.jar
    sudo su youtrack -l
    cd /usr/local/youtrack
    wget http://download.jetbrains.com/charisma/${theFile} -O ${theFile}
    
    Restart YouTrack::

    sudo /etc/init.d/youtrack restart

    Attention: Pay attention to special upgrade instructions like in this case Jetbrains -> Youtrack -> Try -> Upgrading Instructions.

    Tip: What I adjusted:

    • export JAVA_HOME=/usr/lib/jvm/java-8-oracle
    • LOG=/dev/null # I don’t want to log to my SSD
    • exec $JAVA_HOME/bin/java -XX:MaxPermSize=1024m -Xmx1g -jar $JAR $PORT >> $LOG 2>&1 &

Be happy - use YouTrack

And, finally, in my case:

  1. Goto http://localhost:8112

    Enjoy!

Comments

comments powered by Disqus

Previous topic

Howto SSH

Next topic

Troublesome Switching between Tabs and Spaces in PhpStorm

Tags

Archives

Languages

Recent Posts

This Page