• systemd init script?

  • Problems with installing OpenKM? No problemo, the solution is closer than you think.
Problems with installing OpenKM? No problemo, the solution is closer than you think.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #40391  by insuranceguy
 
Can I get an OpenKM dev or Linux guru to chime in here?

Debian Linux is now using systemd out of the box...how about a proper systemd .service file? Here's what I've managed to figure out so far:

# cat /etc/systemd/system/tomcat.service
Code: Select all
[Unit]
Description=Apache Tomcat Web Application Container

[Service]
User=root
Group=root
TimeoutStartSec=120
TimeoutStopSec=120
EnvironmentFile=-/etc/default/tomcat
After=network-online.target
KillMode=none

ExecStart=/usr/bin/env ${JAVA_HOME}/bin/java \
$LOGGING_CONFIG $LOGGING_MANAGER \
$JAVA_OPTS $CATALINA_OPTS \
-classpath ${CLASSPATH} \
-Dcatalina.base=${CATALINA_BASE} \
-Dcatalina.home=${CATALINA_HOME} \
-Djava.endorsed.dirs=${JAVA_ENDORSED_DIRS} \
-Djava.io.tmpdir=${CATALINA_TMPDIR} \
org.apache.catalina.startup.Bootstrap \
start

ExecStop=/usr/bin/env ${JAVA_HOME}/bin/java \
$LOGGING_MANAGER \
$JAVA_OPTS \
-classpath ${CLASSPATH} \
-Dcatalina.base=${CATALINA_BASE} \
-Dcatalina.home=${CATALINA_HOME} \
-Djava.endorsed.dirs=${JAVA_ENDORSED_DIRS} \
-Djava.io.tmpdir=${CATALINA_TMPDIR} \
org.apache.catalina.startup.Bootstrap \
stop

[Install]
WantedBy=multi-user.target
Inspiration drawn from here:
http://homepage.ntlworld.com/jonathan.d ... omcat.html
http://unquietwiki.blogspot.com/2015/05 ... at-as.html

Disclaimer: This may not be working 100% correctly! But it has been working fine in my setup (two users, 1.4 GB repo). I used this as an excuse to learn systemd, so I *barely* know what I am doing (ie. the service is running as root :roll: ). But it just seemed more natural to start and stop Tomcat with a systemd service file in the latest Debian. Also, the first link above has some pretty scathing things to say about the default Tomcat catalina.sh script, so I used it to deconstruct catalina.sh and try to get the proper Tomcat systemd startup.

Someone that knows...please help!


p.s. The script above makes reference to a tomcat environment file, I think this was from the original setup with catalina.sh?

# cat /etc/default/tomcat
Code: Select all
CATALINA_HOME=/opt/tomcat
CATALINA_BASE=/opt/tomcat
CATALINA_TMPDIR=/opt/tomcat/temp
JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre
CLASSPATH=/opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
JRE_HOME=/usr
LOGGING_CONFIG="-Dnop"
LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
JAVA_OPTS=" -Xms256m -Xmx1256m -XX:PermSize=256m -XX:MaxPermSize=512m -Djava.awt.headless=true -Dlog4j.configuration=file:/opt/tomcat/conf/log4j.properties -Dfile.encoding=utf-8 -Dmail.mime.ignoreunknownencoding=true"
 #40405  by pavila
 
Hi,

Why don't set ExecStart & ExecStop this way?
Code: Select all
ExecStart=$CATALINA_HOME/bin/startup.sh
ExecStop=$CATALINA_HOME/bin/shutdown.sh
It's shorter and less error prone.
 #40823  by farkinid
 
Hi OP,

I know this is a little late but my startup script for systemd is quite different from yours. When I tried to use your method, I kept running into errors. I suspect the environment file did not agree with my configuration. So I decided to directly place the environments in the systemd service file as well as incorporate pavila's suggestion.

My service file is as follows :-
Code: Select all
Tomcat service file for systemd
===============================

#Systemd unit file for tomcat. Aka this can go horribly wrong

[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/java-7-openjdk-amd64/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target
I referenced this site : https://wolfpaulus.com/journal/software/tomcat-jessie/

I also made a system user called tomcat. So this enables the service to start without root.

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.