Java Service Startup Script in Linux

Source: Internet
Author: User

#! /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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.