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

116 lines
2.7 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
6 months ago
export LC_ALL="en_US.UTF-8"
# echo $DIR
3 years ago
4 years ago
PATH=$PATH:$DIR/bin
6 months ago
if [ -f ${DIR}/bin/activate ];then
source ${DIR}/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
mw_start_task()
{
6 months ago
isStart=$(ps aux |grep 'panel_task.py'|grep -v grep|awk '{print $2}')
3 years ago
if [ "$isStart" == '' ];then
2 years ago
echo -e "starting mw-tasks... \c"
6 months ago
cd $DIR && python3 panel_task.py >> ${DIR}/logs/panel_task.log 2>&1 &
3 years ago
sleep 0.3
6 months ago
isStart=$(ps aux |grep 'panel_task.py'|grep -v grep|awk '{print $2}')
3 years ago
if [ "$isStart" == '' ];then
2 years ago
echo -e "\033[31mfailed\033[0m"
echo '------------------------------------------------------'
6 months ago
tail -n 20 $DIR/logs/panel_task.log
2 years ago
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 months ago
cd ${DIR}/web && gunicorn -c setting.py app:app
3 years ago
#安全启动
mw_start_task
7 years ago
}
7 years ago
mw_start_debug(){
6 months ago
if [ ! -f $DIR/logs/panel_task.log ];then
echo '' > $DIR/logs/panel_task.log
2 years ago
fi
6 months ago
python3 panel_task.py >> $DIR/logs/panel_task.log 2>&1 &
port=7200
2 years ago
if [ -f /www/server/mdserver-web/data/port.pl ];then
port=$(cat /www/server/mdserver-web/data/port.pl)
fi
6 months ago
if [ -f ${DIR}/data/port.pl ];then
port=$(cat ${DIR}/data/port.pl)
fi
5 months ago
# cd ${DIR}/web && gunicorn -b :${port} -k eventlet -w 1 app:app
cd ${DIR}/web && gunicorn -b :${port} -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
7 years ago
}
6 months ago
mw_start_panel(){
port=7200
if [ -f ${DIR}/data/port.pl ];then
port=$(cat ${DIR}/data/port.pl)
fi
5 months ago
# cd ${DIR}/web && gunicorn -b :${port} -k eventlet -w 1 app:app
cd ${DIR}/web && gunicorn -b :${port} -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
6 months ago
3 years ago
}
6 months ago
mw_start_bgtask(){
cd ${DIR}/web && gunicorn -c setting.py app:app
cd ${DIR} && python3 panel_task.py
12 months ago
}
3 years ago
7 years ago
mw_stop()
{
6 years ago
PLIST=`ps -ef|grep app:app |grep -v grep|awk '{print $2}'`
6 months ago
for i in $PLIST
6 years ago
do
2 years ago
kill -9 $i > /dev/null 2>&1
6 years ago
done
6 months ago
PIDS=`ps -ef|grep panel_task.py | grep -v grep |awk '{print $2}'`
6 months ago
for p in $PIDS
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
;;
6 months ago
'panel')
3 years ago
mw_stop
6 months ago
mw_start_panel
3 years ago
;;
6 months ago
'task')
6 months ago
# mw_stop
6 months ago
mw_start_bgtask
12 months ago
;;
7 years ago
esac