Install YouTrack JAR as a Service on Linux
This page provides two sample methods that you can use to install and run YouTrack JAR as a service on *nix-like machines:
A verified method that we have used at JetBrains to run the YouTrack JAR.
An alternative method for running YouTrack JAR on Ubuntu.
YouTrack JAR Installation for Linux
The instructions that are provided in this setup guide have been used by the JetBrains development team to install and run YouTrack JAR in a Linux environment.
Prerequisites
To perform this installation, verify that the following prerequisites are met:
You have installed Oracle Java Runtime Environment 8 or later.
Any external hostname (proxy hostname) is resolvable from the actual host where YouTrack is installed.
Installation
The following procedure describes how to install and run YouTrack JAR as a service on Linux or another *nix-like operating system. The method for adding a startup script that is used in this setup has been tested in environments similar to the Red Hat Linux operating system.
To install the YouTrack JAR distribution as a service on Linux:
Download the JAR distribution from the JetBrains website.
Create a user account to run the YouTrack service. For example,
youtrack
. Theyoutrack
user account manages YouTrack data and services.
adduser youtrack --disabled-password
Download the Tanuki Java Service Wrapper that is compatible with your CPU. For an Intel-based machine, use the following commands:
cd ~youtrack wget https://wrapper.tanukisoftware.com/download/3.5.30/wrapper-linux-x86-64-3.5.30.tar.gz
- Extract the wrapper archive to the home directory of the service user account.
For usability, we also recommend that you rename the wrapper directory. For example,
standalone
.tar -xzf wrapper-linux-x86-64-3.5.30.tar.gz mv wrapper-linux-x86-64-3.5.30 standalone
The directory structure for the wrapper should be similar to the following example:
./standalone ./standalone/bin ./standalone/conf ./standalone/doc ./standalone/lib ./standalone/logs ./standalone/src
Copy the YouTrack JAR file to the wrapper directory:
cp youtrack-<version>.jar ~youtrack/standalone/
Create a soft link to the JAR file:
cd ~youtrack/standalone/ ln -s youtrack-<version>.jar youtrack.jar
- Create a system startup script in the
/etc/init.d/
folder. The script is responsible for starting, stopping, and restarting YouTrack.- Copy the following script template: youtrack_initd.template. (Click the link to download a copy of the file to your local directory.)
This template is based on a sample startup script that is included in the wrapper distribution.
Change the settings in the top section of the script to reflect your system environment.
Save the edited template as
youtrack
in the/etc/init.d/
folder.
- Copy the following script template: youtrack_initd.template. (Click the link to download a copy of the file to your local directory.)
- Replace the configuration file of an existing wrapper
~youtrack/standalone/conf/wrapper.conf
with the following configuration file: wrapper.conf. (Click the link to download a copy of the file to your local directory.)Modify the configuration file to match your YouTrack installation.
The
wrapper.conf
file includes references to the following mandatory JVM options:The maximum Permanent Generation memory is set with the JVM option
-XX:MaxMetaspaceSize=256m
.The maximum Java heap size is set with the property
wrapper.java.maxmemory=1536
. Do not set this property lower than1024m
or1g
.
- Run the wrapper to test the installation:
/sbin/service youtrack start
If the test is successful, the following conditions are met:
YouTrack starts successfully.
The
youtrack.pid
file is created in the~youtrack/standalone/
folder.The
wrapper.log
file is created in the~youtrack/standalone/logs/
folder.
Add the new startup script to the system startup scripts sequence:
/sbin/chkconfig --add youtrack
You can stop or restart YouTrack with the following commands:
/sbin/service youtrack stop /sbin/service youtrack restart
- By default, the new YouTrack instance is configured to use TCP port 8080.
You can change this setting in the
wrapper.conf
file (replace 8080 in linewrapper.app.parameter.2=8080
with the desired port value). If you run YouTrack behind a reverse proxy server, you can configure the forwarding ports on the proxy server.
After installation, you can set up YouTrack to run behind a reverse proxy server. For instructions, see Reverse Proxy Configuration.
Alternative YouTrack JAR Installation for Ubuntu 14.04+
The following setup is based on an installation guide that was provided by one of our users. This setup is configured for an environment that uses Oracle JDK 8+.
To install YouTrack from a JAR as a Service under Linux:
Add a dedicated user account for YouTrack:
sudo adduser youtrack --disabled-password
Create an
init.d
script:sudo vim /etc/init.d/youtrack
Paste the following code into the init.d script:
#! /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
- Save the file:
Press Esc to exit.
Enter
:x
.Press Enter.
Make the script file executable and register it as an init-script:
sudo chmod +x /etc/init.d/youtrack sudo update-rc.d youtrack defaults
Create a logging subdirectory:
sudo mkdir /var/log/youtrack sudo chown youtrack:youtrack /var/log/youtrack
Create a startup script:
sudo vim /home/youtrack/youtrack.sh
Paste the following code into the startup script (
youtrack.sh
).#! /bin/sh ### # YouTrack startup script ### export HOME=/home/youtrack export JAVA_HOME=/usr/bin/java NAME=youtrack PORT=8112 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 -Xmx1g -XX:MaxMetaspaceSize=256m -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 ;; restart|force-reload) d_stop d_start ;; *) echo "Usage: $0 {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0
Modify the
JAVA_HOME
to match your local environment.Modify the
your.domain.tld
in theBASEDIR
definition to match the YouTrack service domain name. For example,BASEDIR=/srv/www/youtrack.example.com
- Save the file:
Press Esc to exit.
Enter
:x
.Press Enter.
Change the owner to the YouTrack user account and make the script file executable:
sudo chown youtrack:youtrack /home/youtrack/youtrack.sh sudo chmod +x /home/youtrack/youtrack.sh
Download the latest YouTrack JAR package (replace <version> with the current version, accordingly):
wget https://download.jetbrains.com/charisma/youtrack-<version>.jar –P /srv/www/<your.domain.tld> sudo chown youtrack:youtrack /srv/www/<your.domain.tld>/youtrack-<version>.jar
Start YouTrack:
sudo service youtrack start
Update Your YouTrack Installation
Updating YouTrack is pretty simple. You just need to re-execute the commands from step 13 above, remove the old JAR file, and restart YouTrack.
wget https://download.jetbrains.com/charisma/youtrack-<version>.jar –P /srv/www/<your.domain.tld>
sudo chown youtrack:youtrack /srv/www/<your.domain.tld>/youtrack-<version>.jar
sudo rm –f /srv/www/<your.domain.tld>/youtrack-<OLD-version>.jar
sudo service youtrack restart