Update mw.tpl

pull/632/head
Mr Chen 6 months ago
parent f952f88d9a
commit 87c50e529d
  1. 118
      scripts/init.d/mw.tpl

@ -28,13 +28,13 @@ WORKING='[\033[34m*\033[0m]'
PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export LANG=en_US.UTF-8 export LANG=en_US.UTF-8
mw_path={$SERVER_PATH} PANEL_DIR={$SERVER_PATH}
ROOT_PATH=$(dirname "$mw_path") ROOT_PATH=$(dirname "$PANEL_DIR")
PATH=$PATH:$mw_path/bin PATH=$PATH:$mw_path/bin
if [ -f $mw_path/bin/activate ];then if [ -f ${PANEL_DIR}/bin/activate ];then
source $mw_path/bin/activate source ${PANEL_DIR}/bin/activate
if [ "$?" != "0" ];then if [ "$?" != "0" ];then
echo "load local python env fail!" echo "load local python env fail!"
fi fi
@ -45,8 +45,8 @@ mw_start_panel()
isStart=`ps -ef|grep 'gunicorn -c setting.py app:app' |grep -v grep|awk '{print $2}'` isStart=`ps -ef|grep 'gunicorn -c setting.py app:app' |grep -v grep|awk '{print $2}'`
if [ "$isStart" == '' ];then if [ "$isStart" == '' ];then
echo -e "starting mw-panel... \c" echo -e "starting mw-panel... \c"
cd $mw_path && gunicorn -c setting.py app:app cd ${PANEL_DIR}/web && gunicorn -c setting.py app:app
port=$(cat ${mw_path}/data/port.pl) port=$(cat ${PANEL_DIR}/data/port.pl)
isStart="" isStart=""
while [[ "$isStart" == "" ]]; while [[ "$isStart" == "" ]];
do do
@ -61,7 +61,7 @@ mw_start_panel()
if [ "$isStart" == '' ];then if [ "$isStart" == '' ];then
echo -e "\033[31mfailed\033[0m" echo -e "\033[31mfailed\033[0m"
echo '------------------------------------------------------' echo '------------------------------------------------------'
tail -n 20 ${mw_path}/logs/error.log tail -n 20 ${PANEL_DIR}/logs/panel_error.log
echo '------------------------------------------------------' echo '------------------------------------------------------'
echo -e "\033[31mError: mw-panel service startup failed.\033[0m" echo -e "\033[31mError: mw-panel service startup failed.\033[0m"
return; return;
@ -75,16 +75,16 @@ mw_start_panel()
mw_start_task() mw_start_task()
{ {
isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}') isStart=$(ps aux |grep 'panel_task.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" == '' ];then if [ "$isStart" == '' ];then
echo -e "starting mw-tasks... \c" echo -e "starting mw-tasks... \c"
cd $mw_path && python3 task.py >> ${mw_path}/logs/task.log 2>&1 & cd ${PANEL_DIR} && python3 panel_task.py >> ${PANEL_DIR}/logs/panel_task.log 2>&1 &
sleep 0.3 sleep 0.3
isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}') isStart=$(ps aux |grep 'panel_task.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" == '' ];then if [ "$isStart" == '' ];then
echo -e "\033[31mfailed\033[0m" echo -e "\033[31mfailed\033[0m"
echo '------------------------------------------------------' echo '------------------------------------------------------'
tail -n 20 $mw_path/logs/task.log tail -n 20 ${PANEL_DIR}/logs/panel_task.log
echo '------------------------------------------------------' echo '------------------------------------------------------'
echo -e "\033[31mError: mw-tasks service startup failed.\033[0m" echo -e "\033[31mError: mw-tasks service startup failed.\033[0m"
return; return;
@ -110,7 +110,7 @@ mw_stop_task()
fi fi
echo -e "stopping mw-tasks... \c"; echo -e "stopping mw-tasks... \c";
pids=$(ps aux | grep 'task.py'|grep -v grep|awk '{print $2}') pids=$(ps aux | grep 'panel_task.py'|grep -v grep|awk '{print $2}')
arr=($pids) arr=($pids)
for p in ${arr[@]} for p in ${arr[@]}
do do
@ -154,7 +154,7 @@ mw_status()
echo -e "\033[31mmw not running\033[0m" echo -e "\033[31mmw not running\033[0m"
fi fi
isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}') isStart=$(ps aux |grep 'panel_task.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" != '' ];then if [ "$isStart" != '' ];then
echo -e "\033[32mmw-task (pid $isStart) already running\033[0m" echo -e "\033[32mmw-task (pid $isStart) already running\033[0m"
else else
@ -174,7 +174,7 @@ mw_reload()
do do
kill -9 $p kill -9 $p
done done
cd $mw_path && gunicorn -c setting.py app:app cd ${PANEL_DIR}/web && gunicorn -c setting.py app:app
isStart=`ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}'` isStart=`ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}'`
if [ "$isStart" == '' ];then if [ "$isStart" == '' ];then
echo -e "\033[31mfailed\033[0m" echo -e "\033[31mfailed\033[0m"
@ -192,27 +192,27 @@ mw_reload()
} }
mw_close(){ mw_close(){
echo 'True' > $mw_path/data/close.pl echo 'True' > ${PANEL_DIR}/data/close.pl
} }
mw_open() mw_open()
{ {
if [ -f $mw_path/data/close.pl ];then if [ -f ${PANEL_DIR}/data/close.pl ];then
rm -rf $mw_path/data/close.pl rm -rf ${PANEL_DIR}/data/close.pl
fi fi
} }
mw_unbind_domain() mw_unbind_domain()
{ {
if [ -f $mw_path/data/bind_domain.pl ];then if [ -f ${PANEL_DIR}/data/bind_domain.pl ];then
rm -rf $mw_path/data/bind_domain.pl rm -rf ${PANEL_DIR}/data/bind_domain.pl
fi fi
} }
mw_unbind_ssl() mw_unbind_ssl()
{ {
if [ -f $mw_path/local ];then if [ -f ${PANEL_DIR}/local ];then
rm -rf $mw_path/local rm -rf ${PANEL_DIR}/local
fi fi
if [ -f $mw_path/nginx ];then if [ -f $mw_path/nginx ];then
@ -226,12 +226,12 @@ mw_unbind_ssl()
error_logs() error_logs()
{ {
tail -n 100 $mw_path/logs/error.log tail -n 100 ${PANEL_DIR}/logs/panel_error.log
} }
mw_update() mw_update()
{ {
if [ -f $mw_path/task.py ];then if [ -f ${PANEL_DIR}/task.py ];then
echo "与后续版本差异太大,不再提供更新" echo "与后续版本差异太大,不再提供更新"
exit 0 exit 0
fi fi
@ -251,7 +251,7 @@ mw_update()
mw_update_dev() mw_update_dev()
{ {
if [ -f $mw_path/task.py ];then if [ -f ${PANEL_DIR}/task.py ];then
echo "与后续版本差异太大,不再提供更新" echo "与后续版本差异太大,不再提供更新"
exit 0 exit 0
fi fi
@ -267,14 +267,14 @@ mw_update_dev()
else else
curl --insecure -fsSL https://code.midoks.icu/midoks/mdserver-web/raw/branch/dev/scripts/update_dev.sh | bash curl --insecure -fsSL https://code.midoks.icu/midoks/mdserver-web/raw/branch/dev/scripts/update_dev.sh | bash
fi fi
cd /www/server/mdserver-web cd ${PANEL_DIR}
} }
mw_update_venv() mw_update_venv()
{ {
rm -rf /www/server/mdserver-web/bin rm -rf ${PANEL_DIR}/bin
rm -rf /www/server/mdserver-web/lib64 rm -rf ${PANEL_DIR}/lib64
rm -rf /www/server/mdserver-web/lib rm -rf ${PANEL_DIR}/lib
LOCAL_ADDR=common LOCAL_ADDR=common
cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"") cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"")
@ -287,7 +287,7 @@ mw_update_venv()
else else
curl --insecure -fsSL https://code.midoks.icu/midoks/mdserver-web/raw/branch/dev/scripts/update_dev.sh | bash curl --insecure -fsSL https://code.midoks.icu/midoks/mdserver-web/raw/branch/dev/scripts/update_dev.sh | bash
fi fi
cd /www/server/mdserver-web cd ${PANEL_DIR}
} }
mw_mirror() mw_mirror()
@ -303,7 +303,7 @@ mw_mirror()
else else
bash <(curl --insecure -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh) bash <(curl --insecure -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)
fi fi
cd ${ROOT_PATH}/mdserver-web cd ${ROOT_PATH}
} }
mw_install_app() mw_install_app()
@ -338,12 +338,12 @@ mw_debug(){
mw_force_kill mw_force_kill
port=7200 port=7200
if [ -f $mw_path/data/port.pl ];then if [ -f ${PANEL_DIR}/data/port.pl ];then
port=$(cat $mw_path/data/port.pl) port=$(cat ${PANEL_DIR}/data/port.pl)
fi fi
if [ -d ${ROOT_PATH}/mdserver-web ];then if [ -d ${PANEL_DIR}/web ];then
cd ${ROOT_PATH}/mdserver-web cd ${PANEL_DIR}/web
fi fi
gunicorn -b :$port -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app gunicorn -b :$port -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
} }
@ -445,7 +445,7 @@ mw_connect_pgdb(){
fi fi
pwd=$(cd ${ROOT_PATH}/mdserver-web && python3 ${ROOT_PATH}/mdserver-web/plugins/postgresql/index.py root_pwd) pwd=$(cd ${PANEL_DIR} && python3 ${PANEL_DIR}/plugins/postgresql/index.py root_pwd)
export PGPASSWORD=${pwd} export PGPASSWORD=${pwd}
echo "${ROOT_PATH}/postgresql/bin/psql -U postgres -W" echo "${ROOT_PATH}/postgresql/bin/psql -U postgres -W"
${ROOT_PATH}/postgresql/bin/psql -U postgres -W ${ROOT_PATH}/postgresql/bin/psql -U postgres -W
@ -464,7 +464,7 @@ mw_mongodb(){
AUTH_STR="" AUTH_STR=""
if [[ "$MGDB_AUTH" == "enabled" ]];then if [[ "$MGDB_AUTH" == "enabled" ]];then
pwd=$(cd ${ROOT_PATH}/mdserver-web && python3 ${ROOT_PATH}/mdserver-web/plugins/mongodb/index.py root_pwd) pwd=$(cd ${PANEL_DIR} && python3 ${PANEL_DIR}/plugins/mongodb/index.py root_pwd)
AUTH_STR="-u root -p ${pwd}" AUTH_STR="-u root -p ${pwd}"
fi fi
@ -493,14 +493,14 @@ mw_redis(){
} }
mw_venv(){ mw_venv(){
cd ${ROOT_PATH}/mdserver-web && source bin/activate cd ${PANEL_DIR} && source bin/activate
} }
mw_clean_lib(){ mw_clean_lib(){
cd ${ROOT_PATH}/mdserver-web && rm -rf lib cd ${PANEL_DIR} && rm -rf lib
cd ${ROOT_PATH}/mdserver-web && rm -rf lib64 cd ${PANEL_DIR} && rm -rf lib64
cd ${ROOT_PATH}/mdserver-web && rm -rf bin cd ${PANEL_DIR} && rm -rf bin
cd ${ROOT_PATH}/mdserver-web && rm -rf include cd ${PANEL_DIR} && rm -rf include
} }
case "$1" in case "$1" in
@ -540,35 +540,35 @@ case "$1" in
port=7200 port=7200
scheme=http scheme=http
if [ -f $mw_path/ssl/choose.pl ];then if [ -f ${PANEL_DIR}/ssl/choose.pl ];then
scheme=https scheme=https
fi fi
if [ -f $mw_path/data/port.pl ];then if [ -f ${PANEL_DIR}/data/port.pl ];then
port=$(cat $mw_path/data/port.pl) port=$(cat ${PANEL_DIR}/data/port.pl)
fi fi
if [ ! -f $mw_path/data/default.pl ];then if [ ! -f ${PANEL_DIR}/data/default.pl ];then
echo -e "\033[33mInstall Failed\033[0m" echo -e "\033[33mInstall Failed\033[0m"
exit 1 exit 1
fi fi
password=$(cat $mw_path/data/default.pl) password=$(cat ${PANEL_DIR}/data/default.pl)
if [ -f $mw_path/data/domain.conf ];then if [ -f ${PANEL_DIR}/data/domain.conf ];then
address=$(cat $mw_path/data/domain.conf) address=$(cat ${PANEL_DIR}/data/domain.conf)
fi fi
if [ -f $mw_path/data/admin_path.pl ];then if [ -f ${PANEL_DIR}/data/admin_path.pl ];then
auth_path=$(cat $mw_path/data/admin_path.pl) auth_path=$(cat ${PANEL_DIR}/data/admin_path.pl)
fi fi
if [ "$address" == "" ];then if [ "$address" == "" ];then
v4=$(python3 $mw_path/tools.py getServerIp 4) v4=$(python3 ${PANEL_DIR}/tools.py getServerIp 4)
v6=$(python3 $mw_path/tools.py getServerIp 6) v6=$(python3 ${PANEL_DIR}/tools.py getServerIp 6)
if [ "$v4" != "" ] && [ "$v6" != "" ]; then if [ "$v4" != "" ] && [ "$v6" != "" ]; then
if [ ! -f $mw_path/data/ipv6.pl ];then if [ ! -f ${PANEL_DIR}/data/ipv6.pl ];then
echo 'True' > $mw_path/data/ipv6.pl echo 'True' > ${PANEL_DIR}/data/ipv6.pl
mw_stop mw_stop
mw_start mw_start
fi fi
@ -578,9 +578,9 @@ case "$1" in
address="MW-Panel-Url: ${scheme}://$v4:$port$auth_path" address="MW-Panel-Url: ${scheme}://$v4:$port$auth_path"
elif [ "$v6" != "" ]; then elif [ "$v6" != "" ]; then
if [ ! -f $mw_path/data/ipv6.pl ];then if [ ! -f ${PANEL_DIR}/data/ipv6.pl ];then
# Need to restart ipv6 to take effect # Need to restart ipv6 to take effect
echo 'True' > $mw_path/data/ipv6.pl echo 'True' > ${PANEL_DIR}/data/ipv6.pl
mw_stop mw_stop
mw_start mw_start
fi fi
@ -597,8 +597,8 @@ case "$1" in
echo -e "\033[32mMW-Panel default info!\033[0m" echo -e "\033[32mMW-Panel default info!\033[0m"
echo -e "==================================================================" echo -e "=================================================================="
echo -e "$address" echo -e "$address"
echo -e `python3 $mw_path/tools.py username` echo -e `python3 ${PANEL_DIR}/panel_tools.py username`
echo -e `python3 $mw_path/tools.py password` echo -e `python3 ${PANEL_DIR}/panel_tools.py password`
# echo -e "password: $password" # echo -e "password: $password"
echo -e "\033[33mWarning:\033[0m" echo -e "\033[33mWarning:\033[0m"
echo -e "\033[33mIf you cannot access the panel. \033[0m" echo -e "\033[33mIf you cannot access the panel. \033[0m"
@ -606,6 +606,6 @@ case "$1" in
echo -e "==================================================================" echo -e "=================================================================="
;; ;;
*) *)
cd $mw_path && python3 $mw_path/tools.py cli $1 cd ${PANEL_DIR} && python3 ${PANEL_DIR}/panel_tools.py cli $1
;; ;;
esac esac

Loading…
Cancel
Save