mdserver-web/cli.sh

91 lines
2.1 KiB
Bash
Raw Normal View History

2018-12-12 06:30:42 -05:00
#!/bin/bash
2021-10-31 04:09:33 -04:00
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
DIR=$(cd "$(dirname "$0")"; pwd)
MDIR=$(dirname "$DIR")
2018-12-12 06:30:42 -05:00
2022-06-29 08:10:29 -04:00
2021-10-31 04:09:33 -04:00
PATH=$PATH:$DIR/bin
2021-11-02 06:20:35 -04:00
if [ -f bin/activate ];then
source bin/activate
fi
2018-12-12 06:30:42 -05:00
2022-10-24 14:53:19 -04:00
export LC_ALL="en_US.UTF-8"
2021-11-12 06:08:08 -05:00
2022-07-04 22:54:49 -04:00
mw_start_task()
{
isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" == '' ];then
2023-07-15 08:43:13 -04:00
echo -e "starting mw-tasks... \c"
2022-07-04 22:54:49 -04:00
cd $DIR && python3 task.py >> ${DIR}/logs/task.log 2>&1 &
sleep 0.3
isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" == '' ];then
2023-02-05 02:22:53 -05:00
echo -e "\033[31mfailed\033[0m"
echo '------------------------------------------------------'
tail -n 20 $DIR/logs/task.log
echo '------------------------------------------------------'
echo -e "\033[31mError: mw-tasks service startup failed.\033[0m"
return;
2022-07-04 22:54:49 -04:00
fi
echo -e "\033[32mdone\033[0m"
else
2023-07-15 08:43:13 -04:00
echo "starting mw-tasks... mw-tasks (pid $(echo $isStart)) already running"
2022-07-04 22:54:49 -04:00
fi
}
2018-12-12 06:30:42 -05:00
mw_start(){
2019-02-18 11:01:30 -05:00
gunicorn -c setting.py app:app
2022-07-04 22:54:49 -04:00
#安全启动
mw_start_task
2018-12-12 06:30:42 -05:00
}
2018-12-12 23:56:06 -05:00
mw_start_debug(){
2022-06-29 08:10:29 -04:00
python3 task.py >> $DIR/logs/task.log 2>&1 &
2023-01-16 10:30:12 -05:00
port=7200
if [ -f /www/server/mdserver-web/data/port.pl ];then
port=$(cat /www/server/mdserver-web/data/port.pl)
fi
2023-01-22 14:44:44 -05:00
# gunicorn -b :${port} -k gevent -w 1 app:app
gunicorn -b :${port} -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
2018-12-12 23:56:06 -05:00
}
2022-04-10 02:25:13 -04:00
mw_start_debug2(){
2022-06-29 08:10:29 -04:00
python3 task.py >> $DIR/logs/task.log 2>&1 &
2022-06-24 10:05:09 -04:00
gunicorn -b :7200 -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
2022-04-10 02:25:13 -04:00
}
2018-12-12 06:30:42 -05:00
mw_stop()
{
2019-03-14 00:53:21 -04:00
PLIST=`ps -ef|grep app:app |grep -v grep|awk '{print $2}'`
for i in $PLIST
do
2023-02-05 02:21:45 -05:00
kill -9 $i > /dev/null 2>&1
2019-03-14 00:53:21 -04:00
done
2022-06-30 10:28:29 -04:00
pids=`ps -ef|grep task.py | grep -v grep |awk '{print $2}'`
arr=($pids)
for p in ${arr[@]}
do
2023-02-05 02:21:45 -05:00
kill -9 $p > /dev/null 2>&1
2022-06-30 10:28:29 -04:00
done
2018-12-12 06:30:42 -05:00
}
case "$1" in
'start') mw_start;;
'stop') mw_stop;;
2018-12-12 08:35:04 -05:00
'restart')
mw_stop
mw_start
;;
2018-12-12 23:56:06 -05:00
'debug')
mw_stop
mw_start_debug
;;
2022-04-10 02:25:13 -04:00
'debug2')
mw_stop
mw_start_debug2
;;
2018-12-12 06:30:42 -05:00
esac