Linux Boot starts jar
# add boot command:
# # chmod + x start-all-jar.sh
# # chkconfig-add start-all-jar.sh
# # chkconfig start-all-jar.sh on
= start-all-jar.sh execution file =
#! / 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 +% Ymuri% m% dmurf% M% S`
Today= `date +% Ymury% m% d`
# jar service name #
Cd / data/es/openec/
Ls-l * .jar | awk'{print $NF}'> / etc/init.d/jarname.txt
# start the service
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} start Service #" > > / 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} has been started"
Echo "#" > > / data/es/openec/logs/start-$ {today} _ out.lo
Echo "${I} has been started" / 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 "start the service ${nowtime}: ${_ SERVICE_NAME}"
Echo
Sleep 1
Done
}
# disable the service
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} start Service #" > > / data/es/openec/logs/stop-$ {today} _ out.log
Echo "shutdown service ${servicename}" > > / data/es/openec/logs/stop-$ {today} _ out.log
Echo "shut down the service ${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 "Service ${_ servicename} is running"
Echo
Else
Echo "Service ${_ servicename} has been shut down"
Echo
Fi
Done
}
# restart the service
Function restart_core () {
Stop_core
Start_core
}
Function start () {# start the entry function of the service
Start_core
}
Function stop () {# closes the entry function of the service
Stop_core
}
# Select using case
Case $1 in
Start)
Start_core
Stop)
Stop_core
Status)
Corestatus
*)
Echo "error choice! please input start or stop"
Esac
Exit $RETVA