千家信息网

linux开机启动jar

发表于:2025-01-23 作者:千家信息网编辑
千家信息网最后更新 2025年01月23日,#添加开机启动命令:##chmod +x start-all-jar.sh##chkconfig --add start-all-jar.sh##chkconfig start-all-jar.sh
千家信息网最后更新 2025年01月23日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


0