Skip to content

Commit

Permalink
update script
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Oct 21, 2024
1 parent 676b27e commit 6b34911
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 44 deletions.
1 change: 1 addition & 0 deletions python/ppc_model/ppc_model_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ def register_task_handler():
print(message)
components.logger().info(message)
server.start()
print("Start model service successfully")
63 changes: 32 additions & 31 deletions python/ppc_model/tools/start.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
#!/bin/bash
SHELL_FOLDER=$(cd $(dirname $0);pwd)
LOG_ERROR() {
content=${1}
echo -e "\033[31m[ERROR] ${content}\033[0m"
}

dirpath="$(cd "$(dirname "$0")" && pwd)"
cd $dirpath
LOG_INFO() {
content=${1}
echo -e "\033[32m[INFO] ${content}\033[0m"
}
binary_path=${SHELL_FOLDER}/ppc_model_app.py
cd ${SHELL_FOLDER}
node=$(basename ${SHELL_FOLDER})
node_pid=$(ps aux|grep ${binary_path}|grep -v grep|awk '{print $2}')

# kill crypto process
crypto_pro_num=`ps -ef | grep /ppc/scripts | grep j- | grep -v 'grep' | awk '{print $2}' | wc -l`
for i in $( seq 1 $crypto_pro_num )
if [ ! -z ${node_pid} ];then
echo " ${node} is running, pid is $node_pid."
exit 0
else
nohup ${binary_path} > start.out 2>&1 &
sleep 1.5
fi
try_times=4
i=0
while [ $i -lt ${try_times} ]
do
crypto_pid=`ps -ef | grep /ppc/scripts | grep j- | grep -v 'grep' | awk '{print $2}' | awk 'NR==1{print}'`
kill -9 $crypto_pid
node_pid=$(ps aux|grep ${binary_path}|grep -v grep|awk '{print $2}')
success_flag=$(tail -n20 start.out | grep successfully)
if [[ ! -z ${node_pid} && ! -z "${success_flag}" ]];then
echo -e "\033[32m ${node} start successfully pid=${node_pid}\033[0m"
exit 0
fi
sleep 0.5
((i=i+1))
done

sleep 1

nohup python ppc_model_app.py > start.out 2>&1 &

check_service() {
try_times=5
i=0
while [ -z `ps -ef | grep ${1} | grep python | grep -v grep | awk '{print $2}'` ]; do
sleep 1
((i = i + 1))
if [ $i -lt ${try_times} ]; then
echo -e "\033[32m.\033[0m\c"
else
echo -e "\033[31m\nServer ${1} isn't running. \033[0m"
return
fi
done

echo -e "\033[32mServer ${1} started \033[0m"
}

sleep 5
check_service ppc_model_app.py
echo -e "\033[31m Exceed waiting time. Please try again to start ${node} \033[0m"
53 changes: 40 additions & 13 deletions python/ppc_model/tools/stop.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
#!/bin/bash
SHELL_FOLDER=$(cd $(dirname $0);pwd)

dirpath="$(cd "$(dirname "$0")" && pwd)"
cd $dirpath
LOG_ERROR() {
content=${1}
echo -e "\033[31m[ERROR] ${content}\033[0m"
}

# kill crypto process
crypto_pro_num=`ps -ef | grep /ppc/scripts | grep j- | grep -v 'grep' | awk '{print $2}' | wc -l`
for i in $( seq 1 $crypto_pro_num )
do
crypto_pid=`ps -ef | grep /ppc/scripts | grep j- | grep -v 'grep' | awk '{print $2}' | awk 'NR==1{print}'`
kill -9 $crypto_pid
done
LOG_INFO() {
content=${1}
echo -e "\033[32m[INFO] ${content}\033[0m"
}

sleep 1
binary_path=${SHELL_FOLDER}/ppc_ppc_model_app.py
node=$(basename ${SHELL_FOLDER})
node_pid=$(ps aux|grep ${binary_path}|grep -v grep|awk '{print $2}')
try_times=10
i=0
if [ -z ${node_pid} ];then
echo " ${node} isn't running."
exit 0
fi

ppc_model_app_pid=`ps aux |grep ppc_model_app.py |grep -v grep |awk '{print $2}'`
kill -9 $ppc_model_app_pid
#Stop monitor here
dirs=($(ls -l ${SHELL_FOLDER} | awk '/^d/ {print $NF}'))
for dir in ${dirs[*]}
do
if [[ -f "${SHELL_FOLDER}/${dir}/node.mtail" && -f "${SHELL_FOLDER}/${dir}/stop_mtail_monitor.sh" ]];then
echo "try to start ${dir}"
bash ${SHELL_FOLDER}/${dir}/stop_mtail_monitor.sh &
fi
done

echo -e "\033[32mServer ppc_model_app.py killed. \033[0m"
[ ! -z ${node_pid} ] && kill ${node_pid} > /dev/null
while [ $i -lt ${try_times} ]
do
sleep 1
node_pid=$(ps aux|grep ${binary_path}|grep -v grep|awk '{print $2}')
if [ -z ${node_pid} ];then
echo -e "\033[32m stop ${node} success.\033[0m"
exit 0
fi
((i=i+1))
done
echo " Exceed maximum number of retries. Please try again to stop ${node}"
exit 1

0 comments on commit 6b34911

Please sign in to comment.