Friday, August 29, 2014

IBM Sametime Turn Server as a Linux Service 

Here is an example of how to start the turn server as a service in Linux

just create a file under /etc/init.d/ called turn 

change the permissions to 755 (chmod 755) 

copy paste the code below and modify your TurnHome Variable to point to where yours is located 

I have a complete server for this application so I am seeting high values for heap dumps but you can change them as needed follow IBM performance recommendations.

#!/bin/sh
# *****************************************************************
# chkconfig: 2345 80 30
# description: TURN Service
# Created by jrmedina@mx1.ibm.com                                               
# *****************************************************************

#Variables
   Action=$1
   TurnHome="/TURN_SERVER"
   cd $TurnHome
   ErrLog="${TurnHome}/Errors.log"
   heapSize="-Xms1024m -Xmx2048m -Xmn512m" # Start Maximum Minimum
   uid=$(id | cut -d\( -f1 | cut -d= -f2)
   TurnPid=$(ps aux | grep TurnServer | grep -v grep | awk '{print $2}')
   if [[ $TurnPid == "" ]]
   then
           TurnPid=0
   fi

# Functions

function start
{
        echo "Starting TURN service";
#       run > $ErrLog
        java ${heapSize} -Djava.util.logging.config.file=logging.properties -cp TurnServer.jar:ICECommon.jar:anonTokenAuth.jar com.ibm.turn.server.TurnServer > $ErrLog 2>&1 &
        sleep 1
}

function stop
{
        echo "Stopping TURN service"
        kill -9 $TurnPid
}

# Main
#exec >>$TurnHome/logs/turn.log
case $Action in
        "stop") # Only root can stop the service
                [ $uid -ne 0 ] && exit 4
                stop
                ;;
        "start")
                # Only root can start the service
                [ $uid -ne 0 ] && exit 4
                if [ $TurnPid -gt 0 ]
                then
                        echo "TURN Service is already running"
                else
                        start
                fi
                ;;
        "restart") # Only root can start the service
                [ $uid -ne 0 ] && exit 4
                if [ $TurnPid -gt 0 ]
                then 
                        stop
                fi
                        start
                ;;
        "status")
                if [ $TurnPid -gt 0 ]
                then
                        echo "TURN service (pid $TurnPid) is running..."
                        ps -ef | grep ${TurnPid} | grep -v grep ; netstat -na | grep 3478
                else
                        echo "TURN service is stopped"
                fi
                ;;
        "*")    echo "Usage: turn {start|stop|status|restart}"
                ;;
esac

# EOF