Friday, January 3, 2014

IBM Sametime Turn Server Linux Service auto start - How to create

Today I was in dire need of a Linux RedHat service, where the IBM Sametime TURN server starts up automatically at boot time of the Linux server.

Google was of no help, but as the Turn server is just a jar file that needs to be fired, I did find this one which helped me achieve success:
http://stackoverflow.com/questions/17069543/running-java-process-as-service-in-linux

So, after modifying the script, I was actually able to create the init-script for the Turn server. Here´s the recipe:

My Turn server is installed on /opt/IBM/TURN-Server
If your server is installed in a different directory, edit the script below accordingly.

This is the script which I put into the /etc/init.d folder.
Filename: turnserver.init
Content:

#!/bin/tcsh
#
# chkconfig: 2345 80 30
# description: TURN-service Service
# Created by @robertfarstad, http://blog.robertfarstad.com
# This is a modified version of a script found here: http://stackoverflow.com/questions/17069543/running-java-process-as-service-in-linux
setenv TURN_SERVICE_HOME /opt/IBM/TURN_Server
cd $TURN_SERVICE_HOME

setenv JARS "$TURN_SERVICE_HOME/TurnServer.jar:$TURN_SERVICE_HOME/ICECommon.jar:$TURN_SERVICE_HOME/anonTokenAuth.jar"
setenv PARAMS "-Xms512m -Xmx512m -Xmn128m -Djava.util.logging.config.file=$TURN_SERVICE_HOME/logging.properties -cp $JARS com.ibm.turn.server.TurnServer"

setenv SERVICE_PID  `ps aux | grep TurnServer | grep -v grep | awk '{print $2}'`;

if ( (stop == $1  || restart == $1)) then
    echo "TURN-service stop";
    kill -9 $SERVICE_PID
    setenv SERVICE_PID
endif

if ( start == $1 || restart == $1 ) then
    if($SERVICE_PID) then
        echo "TURN-service is already running"
    else
        echo "TURN-service start";
        /opt/IBM/WebSphere/AppServer/java/bin/java $PARAMS &
    endif
endif

if (status == $1) then
    if($SERVICE_PID) then
        echo "TURN-service (pid $SERVICE_PID) is running...";
    else
        echo "TURN-service is stopped";
    endif
endif

 
The I performed a
chmod 755 /etc/init.d/turnserver.init
command, so that the script is allowed to run.

Then I tested the script by doing a "status", "start" and "stop"
/etc/init.d/turnserver.init status
/etc/init.d/turnserver.init start
/etc/init.d/turnserver.init stop
Be aware: When starting the server manually this way, it seems that the terminal window does not provide me with a correct prompt before I actually press the ENTER key. DO NOT press CTRL+C, as I was tempted to do. This kills the Turn server. Just press enter and the prompt is back normally.

Then I added this script as a service:
chkconfig /etc/init.d/turnserver.init add

This enables me to start, stop and status the server like this:




service turnserver.init status
service turnserver.init start
service turnserver.init stop

Then I added the service to fire up at boot time:
chkconfig turnserver.init on

I then did a "service turnserver.init stop" and checked the process list (ps -ef |grep TurnServer) to see if the server was actually shut down.
I then restarted the Linux server, and after it was back up, I checked the process list to see if the Turn server was actually started. It was!! :-)

No comments: