#添加开机启动命令:
创新互联建站是一家专注于成都网站设计、网站建设与策划设计,永昌网站建设哪家好?创新互联建站做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:永昌等地区。永昌做网站价格咨询:028-86922220
##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