概述
在公司开发的系统包含多个服务进程,每个服务以单独的jvm进程的方式存在。为了节省存储空间以及对不同进程使用的jar包进行统一管理,要求所有服务使用的jar包都存放在同一个目录中,所有进程使用同一个jdk,每个服务有自己单独的目录存放主程序(服务启动逻辑和非共享逻辑)。我的db_service的启停脚本如下:
#!/bin/bash
#author:lixiang
#the script that control the db-service
BASE_DIR=~/smb_cloud
DBSERVICE_DIR=$BASE_DIR/services/db_service
SERVER_NAME="db-service"
PROCESS_NAME="com.dear.simpler.dbrpc.processor.MainProcessor"
JAVA_HOME=~/smb_cloud/environments/jdk
export JAVA=$JAVA_HOME/bin/java
#add libs and service to classpath
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$DBSERVICE_DIR/conf:$(ls $BASE_DIR/environments/libs/java/*.jar | tr 'n' :)$(ls *.jar | tr 'n' :)
LOG_FILE=./db_ctl.log
function running(){
count=`ps aux | grep java | grep $PROCESS_NAME | grep -v grep | wc -l`
if [ $count == 0 ];then
return 1
else
return 0
fi
}
function start_server(){
if running; then
echo "$SERVER_NAME is running."
exit 1
fi
echo $CLASSPATH >>$LOG_FILE
nohup $JAVA com.dear.simpler.dbrpc.processor.MainProcessor 2>&1 >>$LOG_FILE &
sleep 3
if running; then
echo "$SERVER_NAME start success"
else
echo "$SERVER_NAME start fail"
fi
}
function stop_server(){
if ! running; then
echo "$SERVER_NAME is not running."
exit 1
fi
pid=`ps aux | grep java | grep $PROCESS_NAME | grep -v grep | awk {'print$2'}`
kill
$pid
sleep 3
if ! running; then
echo "$SERVER_NAME stop success."
else
kill -9 $pid
sleep 3
if ! running; then
echo "$SERVER_NAME stop success."
else
echo "$SERVER_NAME stop fail."
fi
fi
}
function status(){
if running; then
echo "$SERVER_NAME is running."
else
echo "$SERVER_NAME was stopped."
fi
}
function help() {
echo "Usage: db_ctl {start|status|stop|restart}" >&2
echo "
start:
start the $SERVER_NAME server"
echo "
stop:
stop the $SERVER_NAME server"
echo "
restart:
restart the $SERVER_NAME server"
echo "
status:
get $SERVER_NAME current status,running or stopped."
}
command=$1
shift 1
case $command in
start)
start_server
;;
stop)
stop_server
;;
status)
status
;;
restart)
$0 stop
$0 start
;;
help)
help
;;
*)
help
exit 1
;;
esac
最后
以上就是能干香水为你收集整理的java程序启动脚本的全部内容,希望文章能够帮你解决java程序启动脚本所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复