您好,登錄后才能下訂單哦!
#添加開機啟動命令:
##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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。