1. Install Java (I tried it with Oracle’s Java 8, should also works with openjdk).

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
apt-get install oracle-java8-set-default

 

2. Create a user for youtrack and make an installation folder.

adduser youtrack --disabled-password
mkdir -p /usr/local/youtrack
chown youtrack:youtrack /usr/local/youtrack

 

3. Make an init script.

vim /etc/init.d/youtrack

 

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

 

4. Make the script executable.

chmod 755 /etc/init.d/youtrack
update-rc.d youtrack defaults

 

5. Make a script thats starts running the YouTrack daemon.

vim /usr/local/youtrack/youtrack.sh

 

#! /bin/sh

export HOME=/home/youtrack
export JAVA_HOME=/usr/bin/java

NAME=youtrack
PORT=8112
USR=/usr/local/$NAME
JAR=$USR/`ls -Lt $USR/*.jar | grep -o "$NAME-[Linux. YouTrack JAR as a Service. Alternative Method^/]*.jar" | head -1`
LOG=$USR/$NAME-$PORT.log
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
  exec $JAVA_HOME -Xmx512m -jar $JAR"youtrack.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

 

6. Make the script executable.

chmod 755 /usr/local/youtrack/youtrack.sh

 

7. Download latest YouTrack linux version from JetBrains and put it into /tmp folder.
 

8. Copy it to the installation folder.

cp /tmp/youtrack-[xxx].jar /usr/local/youtrack/youtrack.jar

 

9. Start YouTrack.

/etc/init.d/youtrack restart

 

10. Verify if it’s running.

netstat -tapn|grep 8112

 

11. Configure nginx vhost (should work equally with apache I think).

      location / {
                proxy_pass http://127.0.0.1:8112;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        Host $http_host;
        }

 

12. Restart nginx, load website, setup your YouTrack installation.


0 Comments

Leave a Reply