HowTo - YouTrack on Ubuntu 14.04 LTS (opt. with NginX)

advertisement
Running YouTrack on Ubuntu 14.04(.01) LTS
(optionally with NginX as reverse-proxy)
Prerequisites:
Oracle JDK doesn’t have to be necessarily version 1.5, OpenJDK 7 works, too.
For Ubuntu 14.04(.01) LTS, the package “default-jre-headless” suits just perfectly.
Additionally, this makes setting “java.awt.headless=true” obsolete.
Installing YouTrack JAR as a Service under Linux
All commands have to be prefixed with “sudo ” (notice the whitespace), because there’s no rootaccount available on Ubuntu. Yes, you can activate it. But there’s not a single reason to do so.
For your (and most importantly other customer’s) convenience, I’m going to prefix all commands
accordingly below.
Note: I’ve opted for installing within the YouTrack user’s home-directory. I consider this generally
better, because this is definitely user-space and there’s no way for an attacker to manipulate files
outside /home/<YouTrack account name>. So, there’s no equivalent to the original guide’s 2nd step
in mine.
The commands in their respective order are as follows:
1. Add a new and own user for YouTrack:
sudo adduser youtrack --disabled-password
2. Create init.d-script:
sudo vim /etc/init.d/youtrack
3. Put this inside the newly created file:
#! /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=/home/$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. Save file by exiting with <ESC>, entering “:x” and pressing <ENTER>.
5. Make script file executable and register as init-script:
sudo chmod +x /etc/init.d/youtrack
sudo update-rc.d youtrack defaults
7. Create logging subdirectory:
sudo mkdir /var/log/youtrack
sudo chown youtrack:youtrack /var/log/youtrack
8. Create start-up script:
sudo vim /home/youtrack/youtrack.sh
9. Put this inside the newly created file (modifying “JAVA_HOME” isn’t necessary, if you installed
“default-jre-headless” beforehand):
#! /bin/sh
###
# YouTrack startup script
###
export HOME=/home/youtrack
export JAVA_HOME=/usr/bin/java
NAME=youtrack
PORT=8112
MAXHEAP=512M
BASEDIR=/srv/www/your.domain.tld
JAR=$BASEDIR/`ls -Lt $BASEDIR/*.jar | grep -o "$NAME-[^/]*.jar" | head -1`
LOG=/var/log/$NAME/$NAME-$PORT.log
PID=/run/$NAME/$NAME-$PORT.pid
# Setup proper run environment
if [ ! -d /run/$NAME ]; then
mkdir /run/$NAME
chown $NAME:$NAME /run/$NAME
fi
if [ ! -d /var/log/$NAME ]; then
mkdir /var/log/$NAME
chown $NAME:$NAME /var/log/$NAME
fi
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 $BASEDIR
exec $JAVA_HOME -Xmx$MAXHEAP -jar $JAR $PORT >> $LOG 2>&1 &
echo $! > $PaID
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 |
if [ ! -z "$PID_VALUE" ]; then
kill $PID_VALUE
WAIT_TIME=0
while [ `ps ax | grep $PID_VALUE | grep -v grep |
"$WAIT_TIME" -lt 2 ]
do
sleep 1
WAIT_TIME=$(expr $WAIT_TIME + 1)
done
if [ `ps ax | grep $PID_VALUE | grep -v grep | wc
WAIT_TIME=0
while [ `ps ax | grep $PID_VALUE | grep -v grep
"$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
kill -9 $PID_VALUE
fi
fi
fi
rm -f $PID
fi
awk '{print $1}'`
wc -l` -ne 0 -a
-l` -ne 0 ]; then
| wc -l` -ne 0 -a
-l` -ne 0 ]; then
}
case "$1" in
start)
d_start
;;
stop)
d_stop
;;
restart|force-reload)
d_stop
d_start
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
10. Save file by exiting with <ESC>, entering “:x” and pressing <ENTER>.
11. Change owner to youtrack user and make script file executable:
sudo chown youtrack:youtrack /home/youtrack/youtrack.sh
sudo chmod +x /home/youtrack/youtrack.sh
12. Download latest YouTrack JAR package (replace <version> with current version accordingly):
wget http://download.jetbrains.com/charisma/youtrack-<version>.jar –P
/home/youtrack
sudo chown youtrack:youtrack /home/youtrack/youtrack-<version>.jar
13. Download and install NginX (package “nginx-full” is recommended):
sudo apt-get install nginx-full
14. Create a site configuration for YouTrack. Refer to the NginX “default site”-configuration located
at /etc/nginx/sites-available/default or the official manual for further information on
proper configuration.
15. By inserting the following snippet, NginX will act as a reverse-proxy (i.e. making YouTrack
available at the default HTTP port 80):
location / {
proxy_pass
proxy_set_header
proxy_set_header
proxy_set_header
}
http://localhost:8112;
X-Real-IP
$remote_addr;
X-Forwarded-For $proxy_add_x_forwarded_for;
Host
$http_host;
16. Activate YouTrack site configuration by creating a symbolic link:
ln –s /etc/nginx/sites-available/your.domain.tld /etc/nginx/sitesenabled/your.domain.tld
17. Finally, start NginX and YouTrack:
sudo service nginx start
sudo service youtrack start
Congratulations, now your YouTrack instance is up and running at http://your.domain.tld!
Updating YouTrack
Updating YouTrack is pretty simple. You just need to re-execute the commands from step #12,
remove the old JAR file and restart YouTrack:
wget http://download.jetbrains.com/charisma/youtrack-<version>.jar –P
/home/youtrack
sudo chown youtrack:youtrack /home/youtrack/youtrack-<version>.jar
sudo rm –f /home/youtrack/youtrack-<OLDversion>.jar
sudo service youtrack restart
For maximum convenience, we suggest you put YouTrack into maintenance mode before running
the commands for updating above.
Download