#!/bin/sh
### BEGIN INIT INFO
# Provides:dastask
# Required-start: $ALL
# Required-stop: $ALL
# Default-start:2 3 4 5
# default-stop:0 1 6
# Short-description:start and Stop ORS
# Description:dastask ORS SERVER
### End INIT INFO
#该脚本为Linux下启动java程序的通用脚本. That can be invoked as a boot from service script,
#也可以作为启动java程序的独立脚本来使用.
#
#Author: Wuzhenzhong, DATE:2011/7/26
#
#警告!!! : The script Stop section uses the System Kill command to force the termination of the specified Java program process.
#在杀死进程前, no condition checks were made. In some cases, such as when a program is doing a file or database write operation,
#可能会造成数据丢失或数据不完整. If you have to consider this kind of situation, you need to overwrite this script,
#增加在执行kill命令前的一系列检查.
#
#
###################################
#环境变量及程序执行参数
#需要根据实际环境以及Java程序名称来修改这些参数
###################################
#JDK所在路径
Java_home= "/home/yuntest1/data/jdk16"
#执行程序启动所使用的系统用户, it is recommended that you do not use the root account for security reasons
Running_user=yuntest1
#Java程序所在的目录 (previous level of classes)
App_home=/home/yuntest1/data/agent
#拼凑完整的classpath参数, including all jars under the specified Lib directory
Classpath= $APP _home/bin
For i in "$APP _home"/lib/*.jar; Todo
Classpath= "$CLASSPATH": "$i"
Done
#java虚拟机启动参数
Java_opts= ""
###################################
# (function) to determine whether a program has been started
#
#说明:
#使用JDK自带的JPS命令及grep命令组合, accurate lookup pid
#jps plus l parameter to show the full package path for Java
#使用awk, split out PID (parts), and Java program name ($ part)
###################################
#初始化psid变量 (Global)
Psid=0
If [-N "$javaps"]; Then
Psid= ' echo $javaps | awk ' {print '} '
Else
Psid=0
Fi
}
###################################
# (function) Start program
#
#说明:
#1. First call the Checkpid function to refresh the $PSID global variable
#2. If the program is started ($psid is not equal to 0), the prompt program is started
#3. If the program is not started, execute the start command line
#4. Call the Checkpid function again after starting the command execution
#5. If the result of step 4 can confirm the PID of the program, print [OK], otherwise print [Failed]
#注意: Echo-n indicates that after printing characters, do not wrap lines
#注意: Use of "Nohup >/dev/null 2>&1 &"
###################################
Start () {
Checkpid
If [$psid-ne 0]; Then
echo "================================"
echo "warn: $APP _mainclass already started! (pid= $psid) "
echo "================================"
Else
Echo-n "Starting $APP _mainclass ..."
java_cmd= "Nohup $JAVA _home/bin/java $JAVA _opts-dapp_home= $APP _home-classpath $CLASSPATH $APP _mainclass >/dev/ Null 2>&1 & "
su-$RUNNING _user-c "$JAVA _cmd"
Checkpid
If [$psid-ne 0]; Then
echo "(pid= $psid) [OK]"
Else
echo "[Failed]"
Fi
Fi
}
###################################
# (function) Stop program
#
#说明:
#1. First call the Checkpid function to refresh the $PSID global variable
#2. If the program is started ($psid is not equal to 0), start the execution stop, otherwise the prompt program is not running
#3. Using the kill-9 PID command to force the kill process
#4. Follow the KILL command line immediately thereafter, and immediately view the return value of the previous command: $?
#5. If the result of step 4 is equal to 0, print [OK], otherwise print [Failed]
#6. To prevent Java programs from being started more than once, this increases the process of repeatedly checking, and repeatedly kills the processing (recursive call stop).
#注意: Echo-n indicates that after printing characters, do not wrap lines
#注意: In Shell programming, "$?" represents the return value of the previous command or a function
###################################
Stop () {
Checkpid
If [$psid-ne 0]; Then
Echo-n "Stopping $APP _mainclass ... (pid= $psid) "
su-$RUNNING _user-c "Kill-9 $psid"
If [$?-eq 0]; Then
echo "[OK]"
Else
echo "[Failed]"
Fi
Checkpid
If [$psid-ne 0]; Then
Stop
Fi
Else
echo "================================"
echo "warn: $APP _mainclass is not running"
echo "================================"
Fi
}
###################################
# (function) Check program running status
#
#说明:
#1. First call the Checkpid function to refresh the $PSID global variable
#2. If the program is started ($psid is not equal to 0), the prompt is running and represents the PID
#3. Otherwise, the prompt program is not running
###################################
Status () {
Checkpid
If [$psid-ne 0]; Then
echo "$APP _mainclass is running! (pid= $psid) "
Else
echo "$APP _mainclass is not running"
Fi
}
###################################
#读取脚本的第一个参数 ($) to make a judgment
#参数取值范围: {Start|stop|restart|status|info}
#如参数不在指定范围之内, print help information
###################################
Case "$" in
' Start ')
Start
;;
' Stop ')
Stop
;;
' Restart ')
Stop
Start
;;
' Status ')
Status
;;
' Info ')
Info
;;
*)
echo "Usage: $ {Start|stop|restart|status|info}"
Exit 1
Esac
Exit 0
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