set up youtrack on ubuntu 16.10

sudo apt-get update
sudo apt-get install openjdk-8-jre
sudo apt-get install nginx
sudo adduser youtrack --disabled-password
sudo mkdir -p /usr/local/youtrack
sudo chown youtrack.youtrack /usr/local/youtrack
sudo nano /etc/init.d/youtrack
#! /bin/sh

export HOME=/home/youtrack

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 service youtrack {start|stop|restart}" >&2
 exit 1
 ;;
esac

exit 0



sudo chmod +x /etc/init.d/youtrack
sudo /usr/sbin/update-rc.d youtrack defaults
sudo nano /usr/local/youtrack/youtrack.sh
#! /bin/sh

export HOME=/home/youtrack

NAME=youtrack
PORT=8080
USR=/usr/local/$NAME
JAR=$USR/`ls -Lt $USR/*.jar | grep -o “$NAME-[^/]*.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 -Xmx1g -XX:MaxPermSize=250m -Djava.awt.headless=true -Djava.security.egd=/dev/zrandom -Djetbrains.youtrack.disableBrowser=true -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

sudo chmod +x /usr/local/youtrack/youtrack.sh
sudo service youtrack start
sudo nano /etc/nginx/sites-available/youtrack
server {
 listen 80;

 server_name track.site.tk;

 location / {
 proxy_pass http://localhost:8080;
 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;
 }


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s