#! /Bin/bash
# Check whether the port is occupied
Function testport (){
If netstat-an | egrep ": $1. * listen">/dev/null
Then
Return 0
Else
Return 1
Fi
}
# Check whether the process has been started
Function testrun (){
If test-F $1
Then
PID = 'cat $1'
If PS ax 2>/dev/null | egrep "^ * $ PID. * $2">/dev/null
Then
Return 0
Else
Rm $1
Return 1
Fi
Else
Return 1
Fi
}
Java_home =/usr/Java/jdk1.6.0 _ 21
Classpath =.: $ java_home/lib: $ jre_home/lib: $ classpath
Path = $ java_home/bin: $ jre_home/bin: $ path
Ttcard_home =/opt/ttcard
Classpath = $ classpath: $ ttcard_home/lib/c3p0-0.9.1.2.jar: $ ttcard_home/lib/jtds-1.2.5.jar: $ ttcard_home/lib/log4j-1.2.16.jar: $ ttcard_home/bin
Export java_home classpath path
Case $1 in
"Start ")
If testrun/opt/ttcard/server. PID Java
Then
Echo "Transaction Server is already running! "
Else
If testport 10002
Then
Echo "another Transaction Server is already running! "
Else
Echo "Starting Transaction Server ..."
# Java-xms512m-xmx1024m com. ttcard. transactionserver
Nohup Java-xms512m-xmx1024m com. ttcard. transactionserver>/dev/null 2> & 1 &
Echo $! >/Opt/ttcard/server. PID
Fi
Fi
;;
"Stop ")
If test-F/opt/ttcard/server. PID
Then
Kill 'cat/opt/ttcard/server. Pi'>/dev/null 2> & 1
Echo "Stopping Transaction Server ..."
Sleep 5
Test-F/opt/ttcard/server. PID & Rm-F/opt/ttcard/server. PID
Else
Echo "Transaction Server is not running ."
Fi
;;
"Reload ")
If test-F/opt/ttcard/server. PID
Then
Kill-HUP 'cat/opt/ttcard/server. Pi'>/dev/null 2> & 1
Echo "reload Transaction Server ..."
Else
Echo "Transaction Server is not running ."
Fi
;;
*)
Echo "Transaction Server usage :"
Echo ""
Echo "start Transaction Server"
Echo "Stop Transaction Server"
Echo "reload Transaction Server"
;;
Esac