Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/cli.sh

95 lines
2.2 KiB

7 years ago
#!/bin/bash
2 years ago
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
4 years ago
DIR=$(cd "$(dirname "$0")"; pwd)
MDIR=$(dirname "$DIR")
7 years ago
3 years ago
4 years ago
PATH=$PATH:$DIR/bin
4 years ago
if [ -f bin/activate ];then
source bin/activate
2 years ago
if [ "$?" != "0" ];then
echo "load local python env fail!"
fi
4 years ago
fi
7 years ago
3 years ago
export LC_ALL="en_US.UTF-8"
4 years ago
3 years ago
mw_start_task()
{
isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" == '' ];then
2 years ago
echo -e "starting mw-tasks... \c"
3 years ago
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
2 years ago
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;
3 years ago
fi
echo -e "\033[32mdone\033[0m"
else
2 years ago
echo "starting mw-tasks... mw-tasks (pid $(echo $isStart)) already running"
3 years ago
fi
}
7 years ago
mw_start(){
6 years ago
gunicorn -c setting.py app:app
3 years ago
#安全启动
mw_start_task
7 years ago
}
7 years ago
mw_start_debug(){
3 years ago
python3 task.py >> $DIR/logs/task.log 2>&1 &
2 years ago
port=7200
if [ -f /www/server/mdserver-web/data/port.pl ];then
port=$(cat /www/server/mdserver-web/data/port.pl)
fi
2 years ago
# gunicorn -b :${port} -k gevent -w 1 app:app
gunicorn -b :${port} -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
7 years ago
}
3 years ago
mw_start_debug2(){
3 years ago
python3 task.py >> $DIR/logs/task.log 2>&1 &
3 years ago
gunicorn -b :7200 -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
3 years ago
}
7 years ago
mw_stop()
{
6 years ago
PLIST=`ps -ef|grep app:app |grep -v grep|awk '{print $2}'`
for i in $PLIST
do
2 years ago
kill -9 $i > /dev/null 2>&1
6 years ago
done
pids=`ps -ef|grep task.py | grep -v grep |awk '{print $2}'`
arr=($pids)
for p in ${arr[@]}
do
2 years ago
kill -9 $p > /dev/null 2>&1
done
7 years ago
}
case "$1" in
'start') mw_start;;
'stop') mw_stop;;
7 years ago
'restart')
mw_stop
mw_start
;;
7 years ago
'debug')
mw_stop
mw_start_debug
;;
3 years ago
'debug2')
mw_stop
mw_start_debug2
;;
7 years ago
esac