Thursday, January 9, 2014

IBM Sametime 9 - Start solidDB as a Service - redhat - script for your liking

On the Video Manager server, which is Linux Only, there´s also an IBM SolidDB database server that comes bundled with the VMGR installation.

When restarting the VMGR, which is WebSphere based, you should also restart the solidDB, according to this technote: http://www-01.ibm.com/support/docview.wss?uid=swg21649416

The VMGR websphere server has a startup script that you can enable to launch at boot-time just by typing in the command:
cd /etc/init.d
chkconfig STMediaServer_was.init on
So, in order for me to achieve a solidDB auto-startup when the server boots, and also, making it easier for me to stop and start the solidDB server, I created this script:

Note: The script has to be stored in the "/etc/init.d" folder.
The script file name is: "soliddb"
#!/bin/tcsh
# chkconfig: 2345 80 30
# description: SOLIDDB-service Service
# Created by @robertfarstad, http://blog.robertfarstad.com

setenv USER "admin"
setenv PASS "admin"
setenv SERVER "tcp localhost 2315"
setenv STOPARGS "stopargs.sql"
setenv PTH "/opt/solidDB/soliddb-7.0/bin/"

cd $PTH

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

if (start == $1) then
    if($SERVICE_PID) then
        echo "-----------> SOLIDB-server is already running";
    else
        echo "-----------> SOLIDDB is not running";
        echo "-----------> SOLIDDB-server starting";
        /opt/solidDB/soliddb-7.0/bin/solid -c /opt/solidDB/soliddb-7.0/eval_kit/standalone
        echo "-----------> SolidDB started";
    endif
endif

if (stop == $1) then
    if ($SERVICE_PID) then
        echo "------------> SOLIDDB-service stopping";
        ./solsql "$SERVER" $USER $PASS $STOPARGS
        echo "------------> Waiting for server to stop";
        sleep 1;
        echo ".";
        sleep 1;
        echo "..";
        sleep 1;
        echo "...";
        sleep 1;
        echo "....";
        sleep 1;
        echo ".....";
        sleep 1;
        echo "......";
        sleep 1;
        echo ".......";
        sleep 1;
        echo "........";
        sleep 1;
        echo ".........";
        sleep 1;
        echo "..........";
        sleep 1;
        echo "...........";

        echo "------------> SOLIDDB-service stopped";
    else
        echo "------------> SolidDB already stopped";
    endif
endif

if(restart == $1) then
    if($SERVICE_PID) then
        echo "-------------> SOLIDB-server is already running";
        echo "-------------> Stopping SOLIDDB";
        ./solsql "$SERVER" $USER $PASS $STOPARGS
        echo "-------------> Pausing for 20 secs before restarting";
        sleep 20;

        echo "-------------> Starting SOLIDDB";
        /opt/solidDB/soliddb-7.0/bin/solid -c /opt/solidDB/soliddb-7.0/eval_kit/standalone
        echo "-------------> SolidDB started";
    else
        echo "-------------> SOLIDDB is not running";
        echo "-------------> SOLIDDB-service is starting";
        /opt/solidDB/soliddb-7.0/bin/solid -c /opt/solidDB/soliddb-7.0/eval_kit/standalone
        echo "-------------> SolidDB started";
    endif
endif

if (status == $1) then
    if($SERVICE_PID) then
        echo "-------------> SOLIDDB Server (pid $SERVICE_PID) is running...";
    else
        echo "-------------> SOLIDDB-Server is not running";
    endif
endif

There´s a reference to a file "stopargs.sql" in this script. This file must be created and stored in the "/opt/solidDB/soliddb-7.0/bin/" directory.

The content of the file is this:
admin command 'shutdown force';
exit;
After the "soliddb" script and the stopargs.sql file is created, you have to run the following commands to enable this as a service

cd /etc/init.d
chkconfig --add soliddb
chkconfig soliddb on
Now you can run the following commands in order to stop/start/restart/check status of the soliddb server:
service soliddb status
service soliddb start
service soliddb stop
service soliddb status
And also, restarting the linux redhat server will autostart the SolidDB server.

Hope this was helpful for you guys. Cheers.


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!! :-)