progress
This commit is contained in:
parent
da28aaca47
commit
2cf15f386f
140
config_server_start.sh
Executable file
140
config_server_start.sh
Executable file
@ -0,0 +1,140 @@
|
||||
#!/bin/bash
|
||||
Script="${0} ${*}"
|
||||
|
||||
function usage {
|
||||
echo "Usage: ${0} [--restart] [--stop] [--once] [--sleep_sec=<num_seconds>]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
for arg in "${@}"
|
||||
do
|
||||
case ${arg} in
|
||||
--restart)
|
||||
Restart=Y
|
||||
shift
|
||||
;;
|
||||
--stop)
|
||||
Stop="Y"
|
||||
shift
|
||||
;;
|
||||
--once)
|
||||
Once="Y"
|
||||
shift
|
||||
;;
|
||||
--sleep_sec=*)
|
||||
SleepSec="${arg#*=}"
|
||||
shift
|
||||
;;
|
||||
-*|--*)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "${SleepSec}" == "" ]
|
||||
then
|
||||
SleepSec=5
|
||||
fi
|
||||
|
||||
RootDir=/home/cvtt/prod
|
||||
CfgSvcDir=${RootDir}/config_service
|
||||
|
||||
export PYTHONPATH="${RootDir}:${PYTHONPATH}"
|
||||
|
||||
Name=config_server
|
||||
ServerPy="${RootDir}/cvttpy/apps/utils/config_server.py"
|
||||
ServicePort=6789
|
||||
ServiceDir=${CfgSvcDir}/data
|
||||
LogDir=${CfgSvcDir}/logs
|
||||
|
||||
|
||||
export PYTHONPATH="${RootDir}:${PYTHONPATH}"
|
||||
|
||||
Cmd="nohup"
|
||||
Cmd="${Cmd} python3"
|
||||
Cmd="${Cmd} ${ServerPy}"
|
||||
Cmd="${Cmd} --port=${ServicePort}"
|
||||
|
||||
|
||||
function check_it {
|
||||
if !(timeout 3 curl -s localhost:${AdminPort}/ping > /dev/null)
|
||||
then
|
||||
echo "${Script} doesn't respond. restarting..."
|
||||
pids=$(ps -ef | grep "--port=${ServicePort}" | grep -v grep | tr -s ' ' |cut -d' ' -f2)
|
||||
echo pids=${pids}
|
||||
if [ "${pids}" != "" ]
|
||||
then
|
||||
kill -9 ${pids}
|
||||
fi
|
||||
echo ${Cmd}
|
||||
eval ${Cmd} && sleep 10
|
||||
fi
|
||||
}
|
||||
|
||||
function start_it {
|
||||
if !(timeout 3 curl -s localhost:${AdminPort}/ping > /dev/null)
|
||||
then
|
||||
pids=$(ps -ef | grep "--port=${ServicePort}" | grep -v grep | tr -s ' ' |cut -d' ' -f2)
|
||||
if [ "${pids}" != "" ]
|
||||
then
|
||||
echo "${0} is already running. pids=(${pids}). Use --restart"
|
||||
exit 0
|
||||
fi
|
||||
echo pids=${pids}
|
||||
if [ "${pids}" != "" ]
|
||||
then
|
||||
kill -9 ${pids}
|
||||
fi
|
||||
echo ${Cmd}
|
||||
eval ${Cmd} && sleep 10
|
||||
fi
|
||||
}
|
||||
|
||||
function kill_it {
|
||||
pids=$(ps -ef |grep "inst_set=${InstrSet}" |grep $(basename ${0}) |grep -v ${$} |grep -v grep |tr -s ' ' |cut -d' ' -f2)
|
||||
|
||||
if [ "${pids}" != "" ]
|
||||
then
|
||||
echo "Killing ${pids} ..."
|
||||
kill -9 ${pids}
|
||||
fi
|
||||
while (timeout 3 curl -s localhost:${AdminPort}/ping > /dev/null)
|
||||
do
|
||||
echo "Shutting down localhost:${AdminPort}/shutdown ..."
|
||||
timeout 10 curl -s localhost:${AdminPort}/shutdown
|
||||
done
|
||||
}
|
||||
|
||||
if [ "${Stop}" == "Y" ] ; then
|
||||
kill_it
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "${Once}" == "Y" ] ; then
|
||||
start_it
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
if [ "${Restart}" == "Y" ]
|
||||
then
|
||||
kill_it
|
||||
else
|
||||
pids=$(ps -ef |grep "inst_set=${InstrSet}" |grep $(basename ${0}) |grep -v ${$} |grep -v grep |tr -s ' ' |cut -d' ' -f2)
|
||||
if [ "${pids}" != "" ]
|
||||
then
|
||||
echo "${0} is already running. pids=(${pids}). Use --restart"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
while true
|
||||
do
|
||||
check_it
|
||||
echo "${Script} is checked" | /usr/bin/ts '[%Y-%m-%d %H:%M:%S]'
|
||||
sleep ${SleepSec}
|
||||
done
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user