linux开机启动jar
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux开机启动jar相关的知识,希望对你有一定的参考价值。
#添加开机启动命令:
##chmod +x start-all-jar.sh
##chkconfig --add start-all-jar.sh
##chkconfig start-all-jar.sh on
============start-all-jar.sh执行文件==============
#! /bin/sh
# chkconfig: 2345 11 80
# description: start and stop all jar
#export DOCKER_IP=192.168.1.128
#DOCKER_IP=${DOCKER_IP:-0.0.0.0}
# Source function library.
. /etc/init.d/functions
RETVAL=0
PATH_VERSION="0.0.1-SNAPSHOT"
nowtime=`date +%Y-%m%d-%M%S`
today=`date +%Y-%m%d`
###### jar 服务名称######
cd /data/es/openec/
ls -l *.jar|awk ‘{print $NF}‘> /etc/init.d/jarname.txt
#启动服务
function start_core(){
if [ ! -d "/data/es/openec/logs" ]; then
mkdir -p /data/es/openec/logs
fi
echo "#########################################################" >> /data/es/openec/logs/start-${today}_out.log
echo "############${nowtime} 启动服务###############" >> /data/es/openec/logs/start-${today}_out.log
for i in `cat /etc/init.d/jarname.txt`
do
_SERVICE_NAME=/data/es/openec/${i}
# _NAME_SUFFIXX="\>"
_PROC_ID=`ps -ef|grep -i ${_SERVICE_NAME}|grep -v "grep"|awk ‘{print $2}‘`
if [ ! $_PROC_ID = "" ]; then
echo "${i} 已经启动"
echo "################" >> /data/es/openec/logs/start-${today}_out.lo
echo "${i} 已经启动" /data/es/openec/logs/start-${today}_out.lo
echo
exit
fi
exec java -Djava.security.egd=file:/dev/./urandom -jar /data/es/openec/${i} >> /data/es/openec/logs/${i}_${nowtime}_out.log &
echo "java -Djava.security.egd=file:/dev/./urandom -jar /data/es/openec/${i} " >> /data/es/openec/logs/start-${today}_out.log
echo "启动服务${nowtime} : ${_SERVICE_NAME}"
echo
sleep 1
done
}
#关闭服务
function stop_core(){
for jarname in `cat /etc/init.d/jarname.txt`
do
servicename=/data/es/openec/${jarname}
_PROC_ID=`ps -ef|grep -i ${servicename}|grep -v "grep"|awk ‘{print $2}‘`
if [ ! $_PROC_ID = "" ]; then
kill -9 $_PROC_ID
echo "#########################################################" >> /data/es/openec/logs/stop-${today}_out.log
echo "############${nowtime} 启动服务###############" >> /data/es/openec/logs/stop-${today}_out.log
echo " 关闭服务${servicename} " >> /data/es/openec/logs/stop-${today}_out.log
echo " 关闭服务${servicename} "
sleep 1
fi
done
}
function corestatus(){
for j in `cat /etc/init.d/jarname.txt`
do
_servicename=/data/es/openec/${j}
_PROC_ID=`ps -ef|grep "${servicename}"|grep -v "grep"|awk ‘{print $2}‘`
if [ ! $_PROC_ID = "" ]; then
echo " 服务${_servicename} 正在运行 "
echo
else
echo " 服务${_servicename} 已经关闭 "
echo
fi
done
}
#重启服务
function restart_core(){
stop_core
start_core
}
function start(){ #启动服务的入口函数
start_core
}
function stop(){ #关闭服务的入口函数
stop_core
}
#使用case选择
case $1 in
start)
start_core
;;
stop)
stop_core
;;
status)
corestatus
;;
*)
echo "error choice ! please input start or stop";;
esac
exit $RETVA
以上是关于linux开机启动jar的主要内容,如果未能解决你的问题,请参考以下文章