Setup OpenKM as automatic starting service

In part 1 we did the basic installation and first start of OpenKM. Right now OpenKM is working but only until  we hit eg. CTRL + C or restart the ODROID. This is not really what we want it to be, so we will add a user under which the service will run and scripts for automatic starting of OpenKM on system start.

First step is to add or service user for OpenKM

sudo useradd -m -s /bin/bash openkm

The next step is to copy the init script example file and adapt it to our needs

sudo cp /etc/init.d/skeleton /etc/init.d/openkm

Here we edit the script according to our needs (or just copy the one from the OpenKM wiki and adapt it).

#!/bin/sh

### BEGIN INIT INFO
# Provides: openkm
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop Apache Tomcat
# Description: Enable Apache Tomcat service provided by daemon.
### END INIT INFO

ECHO=/bin/echo
TEST=/usr/bin/test
TOMCAT_USER=openkm
TOMCAT_HOME=/opt/openkm
TOMCAT_START_SCRIPT=$TOMCAT_HOME/bin/startup.sh
TOMCAT_STOP_SCRIPT=$TOMCAT_HOME/bin/shutdown.sh

$TEST -x $TOMCAT_START_SCRIPT || exit 0
$TEST -x $TOMCAT_STOP_SCRIPT || exit 0

start() {
$ECHO -n “Starting Tomcat”
su – $TOMCAT_USER -c “$TOMCAT_START_SCRIPT &”
$ECHO “.”
}

stop() {
$ECHO -n “Stopping Tomcat”
su – $TOMCAT_USER -c “$TOMCAT_STOP_SCRIPT 60 -force &”
while [ “$(ps -fu $TOMCAT_USER | grep java | grep tomcat | wc -l)” -gt “0” ]; do
sleep 5; $ECHO -n “.”
done
$ECHO “.”
}

case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 30
start
;;
*)
$ECHO “Usage: tomcat {start|stop|restart}”
exit 1
esac
exit 0

Set the permissions on the init file:

sudo chmod 755 /etc/init.d/openkm

Set the permission on the OpenKM directory

sudo chown openkm:openkm /opt/openkm/ -R

Add OpenKM to the services started by default

sudo update-rc.d openkm defaults

If everything works as expected, OpenKM will automatically start after a

sudo reboot

Advertisements

One Response to Setup OpenKM as automatic starting service

  1. Pingback: OpenKM – a DMS for private use | came across

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

%d bloggers like this: