Tomcat 7 JDBC Session Persistence

as root run:

export CATALINA_OPTS=”-Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true”

create table in mysql:

createtabletomcat_sessions (
  session_id     varchar(100) notnullprimarykey,
  valid_session  char(1) notnull,
  max_inactive   intnotnull,
  last_access    bigintnotnull,
  app_name       varchar(255),
  session_data   mediumblob,
  KEYkapp_name(app_name)
);
cd /usr/share/java
wget http://search.maven.org/remotecontent?filepath=mysql/mysql-connector-java/5.1.44/mysql-connector-java-5.1.44.jar
cd /usr/share/tomcat7/lib and run:
/usr/share/tomcat7/lib# ln -s ../../java/mysql-connector.jar mysql-connector.jar
in META-INF create context.xml
paste Manager section:
<Context antiJARLocking="true" >
    <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
        virtualClasspath="/home/link/config"
        searchVirtualFirst="true" />

    <Manager className="org.apache.catalina.session.PersistentManager"
             maxIdleBackup="10">
        <Store className="org.apache.catalina.session.JDBCStore"
               connectionURL="jdbc:mysql://localhost/tomcat?user=root&amp;password=password"
               driverName="com.mysql.jdbc.Driver"
               sessionAppCol="app_name"
               sessionDataCol="session_data"
               sessionIdCol="session_id"
               sessionLastAccessedCol="last_access"
               sessionMaxInactiveCol="max_inactive"
               sessionTable="tomcat_sessions"
               sessionValidCol="valid_session" />
    </Manager>
</Context>
Advertisements

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;
 }