Running YouTrack Issue And Project Tracking Tool On nginx (Debian Wheezy)
YouTrack is an issue and project tracking tool written in Java. This tutorial explains how to serve YouTrack through an nginx webserver on Debian Wheezy.
I do not issue any guarantee that this will work for you!
1 Installing Java
In order to run YouTrack, we need to have Java installed on our server:
apt-get install openjdk-6-jdk openjdk-6-jre unzip
update-alternatives --config java
update-alternatives --config javac
2 Installing YouTrack
Create a YouTrack user and a directory to install YouTrack in:
adduser youtrack --disabled-password
mkdir -p /usr/local/youtrack
chown youtrack:youtrack /usr/local/youtrack
Create the YouTrack init script:
vi /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 |
Make the script executable and set up the system startup links:
chmod 755 /etc/init.d/youtrack
update-rc.d youtrack defaults
The following script is called by the init script and starts the YouTrack daemon on port 8112:
vi /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 |
Make the script executable:
chmod 755 /usr/local/youtrack/youtrack.sh
Next visit http://www.jetbrains.com/youtrack/download/get_youtrack.html, make sure that you select Linux and click on the Download YouTrack button:
Download youtrack-5.0.6.jar to your desktop and then upload it to the /tmp folder of your server. Afterwards, run...
cp /tmp/youtrack-5.0.6.jar /usr/local/youtrack/youtrack.jar
... and start YouTrack:
/etc/init.d/youtrack restart
The YouTrack daemon should now be running on port 8112, as you can verify with the following command:
netstat -tapn|grep 8112
root@server1:/var/www/example.com/web# netstat -tapn|grep 8112
tcp6 0 0 :::8112 :::* LISTEN 11504/java
root@server1:/var/www/example.com/web#
If it is not running, check out the log file /usr/local/youtrack/youtrack-8112.log.
3 Configuring nginx
Next we must configure our nginx vhost through which we want to access YouTrack. You must paste the following configuration into your server {} container (or the nginx Directives field if you use ISPConfig):
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; } |
That's it! Now visit your website, and you should be able to use YouTrack:
4 Links
- YouTrack: http://www.jetbrains.com/youtrack/
- nginx: http://nginx.org/
- Debian: http://www.debian.org/