mdserver-web/cli.sh

86 lines
1.9 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
echo -e "Starting mw-tasks... \c"
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
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;
fi
echo -e "\033[32mdone\033[0m"
else
echo "Starting mw-tasks... mw-tasks (pid $(echo $isStart)) already running"
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 &
2019-02-18 22:37:24 -05:00
gunicorn -b :7200 -k gevent -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
kill -9 $i
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
kill -9 $p
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