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/scripts/init.d/mw.tpl

811 lines
24 KiB

8 years ago
#!/bin/bash
# chkconfig: 2345 55 25
# description: MW Cloud Service
### BEGIN INIT INFO
4 years ago
# Provides: Midoks
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts mw
# Description: starts the mw
### END INIT INFO
3 years ago
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
PLAIN='\033[0m'
BOLD='\033[1m'
SUCCESS='[\033[32mOK\033[0m]'
COMPLETE='[\033[32mDONE\033[0m]'
WARN='[\033[33mWARN\033[0m]'
ERROR='[\033[31mERROR\033[0m]'
WORKING='[\033[34m*\033[0m]'
4 months ago
PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
3 years ago
export LANG=en_US.UTF-8
8 years ago
2 years ago
PANEL_DIR={$SERVER_PATH}
ROOT_PATH=$(dirname "$PANEL_DIR")
2 years ago
PATH=$PATH:${PANEL_DIR}/bin
4 years ago
2 years ago
if [ -f ${PANEL_DIR}/bin/activate ];then
source ${PANEL_DIR}/bin/activate
3 years ago
if [ "$?" != "0" ];then
echo "load local python env fail!"
fi
5 years ago
fi
4 years ago
mw_start_panel()
{
isStart=`ps -ef|grep 'gunicorn -c setting.py app:app' |grep -v grep|awk '{print $2}'`
if [ "$isStart" == '' ];then
4 years ago
echo -e "starting mw-panel... \c"
1 month ago
cd ${PANEL_DIR}/web && gunicorn -c setting.py app:app
2 years ago
port=$(cat ${PANEL_DIR}/data/port.pl)
4 years ago
isStart=""
1 month ago
n=0
4 years ago
while [[ "$isStart" == "" ]];
do
echo -e ".\c"
sleep 0.5
1 month ago
# isStart=$(lsof -n -P -i:$port|grep LISTEN|grep -v grep|awk '{print $2}'|xargs)
isStart=$(ss -tulnp | grep ":$port" |grep LISTEN|grep -v grep|awk '{print $2}'|xargs)
10 months ago
if [[ "$isStart" == "" ]];then
isStart=$(ps -ef|grep python3|grep mdserver-web|grep app:app|awk '{print $2}'|xargs)
fi
4 years ago
let n+=1
if [ $n -gt 60 ];then
4 years ago
break;
8 years ago
fi
4 years ago
done
if [ "$isStart" == '' ];then
4 years ago
echo -e "\033[31mfailed\033[0m"
echo '------------------------------------------------------'
2 years ago
tail -n 20 ${PANEL_DIR}/logs/panel_error.log
4 years ago
echo '------------------------------------------------------'
echo -e "\033[31mError: mw-panel service startup failed.\033[0m"
return;
4 years ago
fi
echo -e "\033[32mdone\033[0m"
8 years ago
else
4 years ago
echo "starting mw-panel... mw(pid $(echo $isStart)) already running"
8 years ago
fi
4 years ago
}
8 years ago
4 years ago
mw_start_task()
{
2 years ago
isStart=$(ps aux |grep 'panel_task.py'|grep -v grep|awk '{print $2}')
8 years ago
if [ "$isStart" == '' ];then
4 years ago
echo -e "starting mw-tasks... \c"
2 years ago
cd ${PANEL_DIR} && python3 panel_task.py >> ${PANEL_DIR}/logs/panel_task.log 2>&1 &
4 years ago
sleep 0.3
2 years ago
isStart=$(ps aux |grep 'panel_task.py'|grep -v grep|awk '{print $2}')
4 years ago
if [ "$isStart" == '' ];then
4 years ago
echo -e "\033[31mfailed\033[0m"
echo '------------------------------------------------------'
2 years ago
tail -n 20 ${PANEL_DIR}/logs/panel_task.log
4 years ago
echo '------------------------------------------------------'
echo -e "\033[31mError: mw-tasks service startup failed.\033[0m"
return;
4 years ago
fi
echo -e "\033[32mdone\033[0m"
8 years ago
else
4 years ago
echo "starting mw-tasks... mw-tasks (pid $(echo $isStart)) already running"
8 years ago
fi
8 years ago
}
4 years ago
mw_start()
{
2 years ago
mw_start_task
2 years ago
mw_start_panel
4 years ago
}
8 years ago
2 years ago
# /www/server/mdserver-web/logs/panel_task.lock && service mw restart_task
4 years ago
mw_stop_task()
8 years ago
{
2 years ago
if [ -f ${PANEL_DIR}/logs/panel_task.lock ];then
4 years ago
echo -e "\033[32mthe task is running and cannot be stopped\033[0m"
1 year ago
return 0
fi
4 years ago
echo -e "stopping mw-tasks... \c";
1 year ago
panel_task=$(ps aux | grep 'panel_task.py'|grep -v grep|awk '{print $2}')
panel_task=($panel_task)
for p in ${panel_task[@]}
8 years ago
do
3 years ago
kill -9 $p > /dev/null 2>&1
8 years ago
done
2 years ago
zzpids=$(ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}')
1 year ago
zzpids=($zzpids)
for p in ${zzpids[@]}
2 years ago
do
kill -9 $p > /dev/null 2>&1
done
8 years ago
echo -e "\033[32mdone\033[0m"
4 years ago
}
8 years ago
4 years ago
mw_stop_panel()
{
4 years ago
echo -e "stopping mw-panel... \c";
1 month ago
pidfile=${PANEL_DIR}/logs/panel.pid
3 years ago
if [ -f $pidfile ];then
pid=`cat $pidfile`
kill -9 $pid > /dev/null 2>&1
rm -f $pidfile
fi
1 year ago
APP_LIST=`ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}'`
APP_LIST=($APP_LIST)
for p in ${APP_LIST[@]}
8 years ago
do
3 years ago
kill -9 $p > /dev/null 2>&1
8 years ago
done
2 years ago
1 year ago
APP_LIST=`ps -ef|grep app:app |grep -v grep|awk '{print $2}'`
APP_LIST=($APP_LIST)
for i in ${APP_LIST[@]}
2 years ago
do
kill -9 $i > /dev/null 2>&1
done
8 years ago
echo -e "\033[32mdone\033[0m"
}
4 years ago
mw_stop()
{
mw_stop_task
4 years ago
mw_stop_panel
4 years ago
}
8 years ago
mw_status()
{
4 years ago
isStart=$(ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}')
if [ "$isStart" != '' ];then
echo -e "\033[32mmw (pid $(echo $isStart)) already running\033[0m"
else
echo -e "\033[31mmw not running\033[0m"
fi
2 years ago
isStart=$(ps aux |grep 'panel_task.py'|grep -v grep|awk '{print $2}')
4 years ago
if [ "$isStart" != '' ];then
echo -e "\033[32mmw-task (pid $isStart) already running\033[0m"
else
echo -e "\033[31mmw-task not running\033[0m"
fi
8 years ago
}
mw_reload()
{
isStart=$(ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}')
if [ "$isStart" != '' ];then
4 years ago
echo -e "reload mw... \c";
8 years ago
arr=`ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}'`
for p in ${arr[@]}
do
kill -9 $p
done
1 month ago
cd ${PANEL_DIR}/web && gunicorn -c setting.py app:app
8 years ago
isStart=`ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}'`
if [ "$isStart" == '' ];then
4 years ago
echo -e "\033[31mfailed\033[0m"
echo '------------------------------------------------------'
tail -n 20 $mw_path/logs/error.log
echo '------------------------------------------------------'
echo -e "\033[31mError: mw service startup failed.\033[0m"
return;
8 years ago
fi
echo -e "\033[32mdone\033[0m"
else
echo -e "\033[31mmw not running\033[0m"
8 years ago
mw_start
8 years ago
fi
}
4 years ago
mw_close(){
1 year ago
cd ${PANEL_DIR} && python3 panel_tools.py cli 14
4 years ago
}
mw_open()
{
1 year ago
cd ${PANEL_DIR} && python3 panel_tools.py cli 15
4 years ago
}
mw_unbind_domain()
{
2 years ago
if [ -f ${PANEL_DIR}/data/bind_domain.pl ];then
rm -rf ${PANEL_DIR}/data/bind_domain.pl
fi
}
2 years ago
mw_unbind_ssl()
{
2 years ago
if [ -f ${PANEL_DIR}/local ];then
rm -rf ${PANEL_DIR}/local
2 years ago
fi
if [ -f $mw_path/nginx ];then
rm -rf $mw_path/nginx
fi
if [ -f $mw_path/ssl/choose.pl ];then
rm -rf $mw_path/ssl/choose.pl
fi
}
8 years ago
error_logs()
{
2 years ago
tail -n 100 ${PANEL_DIR}/logs/panel_error.log
8 years ago
}
9 months ago
# 00----00----00----00----00----00----00----00----00----00----00----00----00----00
function AutoSizeStr(){
NAME_STR=$1
NAME_NUM=$2
NAME_STR_LEN=`echo "$NAME_STR" | wc -L`
NAME_NUM_LEN=`echo "$NAME_NUM" | wc -L`
fix_len=35
remaining_len=`expr $fix_len - $NAME_STR_LEN - $NAME_NUM_LEN`
FIX_SPACE=' '
for ((ass_i=1;ass_i<=$remaining_len;ass_i++))
do
FIX_SPACE="$FIX_SPACE "
done
echo -e " ❖ ${1}${FIX_SPACE}${2})"
}
function ChooseProxyURL(){
clear
echo -e '+---------------------------------------------------+'
echo -e '| |'
echo -e '| ============================================= |'
echo -e '| |'
echo -e '| 欢迎使用 Linux 一键安装mdserver-web面板源码 |'
echo -e '| |'
echo -e '| ============================================= |'
echo -e '| |'
echo -e '+---------------------------------------------------+'
echo -e ''
echo -e '#####################################################'
echo -e ''
echo -e ' 提供以下国内代理地址可供选择: '
echo -e ''
echo -e '#####################################################'
echo -e ''
cm_i=0
for V in ${SOURCE_LIST_KEY[@]}; do
num=`expr $cm_i + 1`
AutoSizeStr "${V}" "$num"
cm_i=`expr $cm_i + 1`
done
echo -e ''
echo -e '#####################################################'
echo -e ''
echo -e " 系统时间 ${BLUE}$(date "+%Y-%m-%d %H:%M:%S")${PLAIN}"
echo -e ''
echo -e '#####################################################'
CHOICE_A=$(echo -e "\n${BOLD}└─ 请选择并输入你想使用的代理地址 [ 1-${SOURCE_LIST_LEN} ]:${PLAIN}")
read -p "${CHOICE_A}" INPUT
# echo $INPUT
if [ "$INPUT" == "" ];then
INPUT=1
TMP_INPUT=`expr $INPUT - 1`
INPUT_KEY=${SOURCE_LIST_KEY[$TMP_INPUT]}
echo -e "\n默认选择[${BLUE}${INPUT_KEY}${PLAIN}]安装!"
fi
if [ "$INPUT" -lt "0" ];then
INPUT=1
TMP_INPUT=`expr $INPUT - 1`
INPUT_KEY=${SOURCE_LIST_KEY[$TMP_INPUT]}
echo -e "\n低于边界错误!选择[${BLUE}${INPUT_KEY}${PLAIN}]安装!"
sleep 2s
fi
if [ "$INPUT" -gt "${SOURCE_LIST_LEN}" ];then
INPUT=${SOURCE_LIST_LEN}
TMP_INPUT=`expr $INPUT - 1`
INPUT_KEY=${SOURCE_LIST_KEY[$TMP_INPUT]}
echo -e "\n超出边界错误!选择[${BLUE}${INPUT_KEY}${PLAIN}]安装!"
sleep 2s
fi
INPUT=`expr $INPUT - 1`
INPUT_KEY=${SOURCE_LIST_KEY[$INPUT]}
HTTP_PREFIX=${PROXY_URL[$INPUT_KEY]}
}
1 year ago
9 months ago
mw_common_proxy(){
HTTP_PREFIX="https://"
1 year ago
LOCAL_ADDR=common
cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"")
if [ ! -z "$cn" ] || [ "$?" == "0" ] ;then
LOCAL_ADDR=cn
fi
9 months ago
if [ "$LOCAL_ADDR" != "common" ];then
# https://github.akams.cn
9 months ago
declare -A PROXY_URL
PROXY_URL["gh_proxy_com"]="https://gh-proxy.com/"
9 months ago
PROXY_URL["github_do"]="https://github.do/"
9 months ago
PROXY_URL["gh_llkk_cc"]="https://gh.llkk.cc/https://"
9 months ago
PROXY_URL["gh_felicity_ac_cn"]="https://gh.felicity.ac.cn/https://"
9 months ago
PROXY_URL["ghfast_top"]="https://ghfast.top/"
9 months ago
PROXY_URL["ghproxy_net"]="https://ghproxy.net/"
PROXY_URL["gh_927223_xyz"]="https://gh.927223.xyz/https://"
PROXY_URL["gh_proxy_net"]="https://gh-proxy.net/"
9 months ago
PROXY_URL["source"]="https://"
SOURCE_LIST_KEY_SORT_TMP=$(echo ${!PROXY_URL[@]} | tr ' ' '\n' | sort -n)
SOURCE_LIST_KEY=(${SOURCE_LIST_KEY_SORT_TMP//'\n'/})
SOURCE_LIST_LEN=${#PROXY_URL[*]}
fi
if [ "$LOCAL_ADDR" != "common" ];then
ChooseProxyURL
9 months ago
if [ "$HTTP_PREFIX" != "https://" ];then
9 months ago
DOMAIN=`echo $HTTP_PREFIX | sed 's|https://||g'`
DOMAIN=`echo $DOMAIN | sed 's|/||g'`
ping -c 3 $DOMAIN > /dev/null 2>&1
if [ "$?" != "0" ];then
9 months ago
echo "无效代理地址:${HTTP_PREFIX}"
9 months ago
exit
fi
fi
fi
}
mw_install(){
if [ -f ${PANEL_DIR}/task.py ];then
echo "与后续版本差异太大,不再提供更新"
exit 0
fi
mw_common_proxy
9 months ago
echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/master/scripts/install.sh")"
2 months ago
bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/master/scripts/update.sh")
2 months ago
mw_clean_lib
9 months ago
bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/master/scripts/install.sh")
1 year ago
}
4 years ago
mw_update()
{
2 years ago
if [ -f ${PANEL_DIR}/task.py ];then
2 years ago
echo "与后续版本差异太大,不再提供更新"
exit 0
fi
9 months ago
mw_common_proxy
9 months ago
echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/master/scripts/update.sh")"
9 months ago
bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/master/scripts/update.sh")
4 years ago
}
mw_update_dev()
2 years ago
{
2 years ago
if [ -f ${PANEL_DIR}/task.py ];then
2 years ago
echo "与后续版本差异太大,不再提供更新"
exit 0
fi
9 months ago
mw_common_proxy
9 months ago
echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh")"
2 months ago
mw_clean_lib
9 months ago
bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh")
2 years ago
cd ${PANEL_DIR}
2 years ago
}
2 months ago
mw_dev()
{
if [ -f ${PANEL_DIR}/task.py ];then
echo "与后续版本差异太大,不再提供更新"
exit 0
fi
mw_common_proxy
echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh")"
bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh")
cd ${PANEL_DIR}
}
2 years ago
mw_update_venv()
4 years ago
{
2 years ago
rm -rf ${PANEL_DIR}/bin
rm -rf ${PANEL_DIR}/lib64
rm -rf ${PANEL_DIR}/lib
2 years ago
9 months ago
mw_common_proxy
9 months ago
echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh")"
9 months ago
bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh")
9 months ago
2 years ago
cd ${PANEL_DIR}
4 years ago
}
mw_mirror()
{
1 year ago
LOCAL_ADDR=common
cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"")
if [ ! -z "$cn" ] || [ "$?" == "0" ] ;then
LOCAL_ADDR=cn
fi
if [ "$LOCAL_ADDR" == "common" ];then
bash <(curl --insecure -sSL https://raw.githubusercontent.com/midoks/change-linux-mirrors/main/change-mirrors.sh)
else
bash <(curl -sSL https://linuxmirrors.cn/main.sh)
fi
2 years ago
cd ${ROOT_PATH}
}
mw_install_app()
{
bash $mw_path/scripts/quick/app.sh
}
4 years ago
mw_close_admin_path(){
1 year ago
cd ${PANEL_DIR} && python3 panel_tools.py cli 6
4 years ago
}
4 years ago
mw_force_kill()
{
PLIST=`ps -ef|grep app:app |grep -v grep|awk '{print $2}'`
for i in $PLIST
do
kill -9 $i
done
pids=`ps -ef|grep task.py | grep -v grep |awk '{print $2}'`
arr=($pids)
for p in ${arr[@]}
do
kill -9 $p
done
}
4 years ago
mw_debug(){
4 years ago
mw_stop
4 years ago
mw_force_kill
4 years ago
port=7200
2 years ago
if [ -f ${PANEL_DIR}/data/port.pl ];then
port=$(cat ${PANEL_DIR}/data/port.pl)
4 years ago
fi
4 years ago
2 years ago
if [ -d ${PANEL_DIR}/web ];then
cd ${PANEL_DIR}/web
4 years ago
fi
2 years ago
# gunicorn -b :$port -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
1 month ago
gunicorn -b :$port -k gevent -w 1 app:app
4 years ago
}
3 years ago
mw_connect_mysql(){
3 years ago
# choose mysql login
declare -A DB_TYPE
if [ -d "${ROOT_PATH}/mysql" ];then
DB_TYPE["mysql"]="mysql"
fi
if [ -d "${ROOT_PATH}/mariadb" ];then
DB_TYPE["mariadb"]="mariadb"
fi
if [ -d "${ROOT_PATH}/mysql-apt" ];then
DB_TYPE["mysql-apt"]="mysql-apt"
fi
if [ -d "${ROOT_PATH}/mysql-yum" ];then
DB_TYPE["mysql-yum"]="mysql-yum"
fi
1 year ago
if [ -d "${ROOT_PATH}/mysql-community" ];then
DB_TYPE["mysql-community"]="mysql-community"
fi
3 years ago
SOURCE_LIST_KEY_SORT_TMP=$(echo ${!DB_TYPE[@]} | tr ' ' '\n' | sort -n)
SOURCE_LIST_KEY=(${SOURCE_LIST_KEY_SORT_TMP//'\n'/})
SOURCE_LIST_LEN=${#DB_TYPE[*]}
3 years ago
if [ "$SOURCE_LIST_LEN" == "0" ]; then
echo -e "no data!"
exit 1
fi
3 years ago
cm_i=0
for M in ${SOURCE_LIST_KEY[@]}; do
num=`expr $cm_i + 1`
AutoSizeStr "${M}" "$num"
cm_i=`expr $cm_i + 1`
done
CHOICE_A=$(echo -e "\n${BOLD}└─ Please select and enter the database you want to log in to [ 1-${SOURCE_LIST_LEN} ]:${PLAIN}")
read -p "${CHOICE_A}" INPUT
if [ "$INPUT" == "" ]; then
3 years ago
INPUT=1
3 years ago
fi
if [ "$INPUT" -lt "0" ] || [ "$INPUT" -gt "${SOURCE_LIST_LEN}" ]; then
echo -e "\nBoundary error not selected!"
exit 1
fi
INPUT=`expr $INPUT - 1`
INPUT_KEY=${SOURCE_LIST_KEY[$INPUT]}
CHOICE_DB=${DB_TYPE[$INPUT_KEY]}
echo "login to ${CHOICE_DB}:"
2 years ago
pwd=$(cd ${ROOT_PATH}/mdserver-web && python3 ${ROOT_PATH}/mdserver-web/plugins/${CHOICE_DB}/index.py root_pwd)
1 year ago
if [ "$pwd" == "admin" ];then
pwd=""
fi
3 years ago
if [ "$CHOICE_DB" == "mysql" ];then
${ROOT_PATH}/mysql/bin/mysql -uroot -p"${pwd}"
fi
3 years ago
if [ "$CHOICE_DB" == "mariadb" ];then
3 years ago
${ROOT_PATH}/mariadb/bin/mariadb -S ${ROOT_PATH}/mariadb/mysql.sock -uroot -p"${pwd}"
3 years ago
fi
1 year ago
if [ "$CHOICE_DB" == "mysql-community" ];then
${ROOT_PATH}/mysql-community/bin/mysql -S ${ROOT_PATH}/mysql-community/mysql.sock -uroot -p"${pwd}"
fi
3 years ago
if [ "$CHOICE_DB" == "mysql-apt" ];then
3 years ago
${ROOT_PATH}/mysql-apt/bin/usr/bin/mysql -S ${ROOT_PATH}/mysql-apt/mysql.sock -uroot -p"${pwd}"
3 years ago
fi
3 years ago
if [ "$CHOICE_DB" == "mysql-yum" ];then
${ROOT_PATH}/mysql-yum/bin/usr/bin/mysql -S ${ROOT_PATH}/mysql-yum/mysql.sock -uroot -p"${pwd}"
fi
2 years ago
}
mw_connect_pgdb(){
if [ ! -d "${ROOT_PATH}/postgresql" ];then
echo -e "postgresql not install!"
exit 1
fi
3 years ago
2 years ago
pwd=$(cd ${PANEL_DIR} && python3 ${PANEL_DIR}/plugins/postgresql/index.py root_pwd)
2 years ago
export PGPASSWORD=${pwd}
echo "${ROOT_PATH}/postgresql/bin/psql -U postgres -W"
2 years ago
${ROOT_PATH}/postgresql/bin/psql -U postgres -W
3 years ago
}
2 years ago
2 years ago
mw_mongodb(){
2 weeks ago
# /www/server/mongodb/bin/mongo --version
2 years ago
CONF="${ROOT_PATH}/mongodb/mongodb.conf"
if [ ! -f "$CONF" ]; then
echo -e "not install mongodb!"
exit 1
fi
MGDB_PORT=$(cat $CONF |grep port|grep -v '#'|awk '{print $2}')
2 years ago
MGDB_AUTH=$(cat $CONF |grep authorization | grep -v '#'|awk '{print $2}')
AUTH_STR=""
if [[ "$MGDB_AUTH" == "enabled" ]];then
2 years ago
pwd=$(cd ${PANEL_DIR} && python3 ${PANEL_DIR}/plugins/mongodb/index.py root_pwd)
2 years ago
AUTH_STR="-u root -p ${pwd}"
fi
2 weeks ago
mg_version=$(/${ROOT_PATH}/mongodb/bin/mongo --version)
# 根据 MongoDB 版本选择使用 mongo 还是 mongosh
if [[ "$mg_version" == *"3.0"* || "$mg_version" == *"3.2"* || "$mg_version" == *"3.4"* || "$mg_version" == *"3.6"* ]]; then
2 weeks ago
CLIEXEC="${ROOT_PATH}/mongodb/bin/mongo --port ${MGDB_PORT} ${AUTH_STR} --authenticationDatabase admin"
2 weeks ago
else
CLIEXEC="${ROOT_PATH}/mongodb/bin/mongosh --port ${MGDB_PORT} ${AUTH_STR}"
fi
2 years ago
echo $CLIEXEC
${CLIEXEC}
2 years ago
}
2 years ago
mw_redis(){
CONF="${ROOT_PATH}/redis/redis.conf"
2 years ago
if [ ! -f "$CONF" ]; then
echo -e "not install redis!"
exit 1
fi
2 years ago
REDISPORT=$(cat $CONF |grep port|grep -v '#'|awk '{print $2}')
REDISPASS=$(cat $CONF |grep requirepass|grep -v '#'|awk '{print $2}')
if [ "$REDISPASS" != "" ];then
REDISPASS=" -a $REDISPASS"
fi
CLIEXEC="${ROOT_PATH}/redis/bin/redis-cli -p $REDISPORT$REDISPASS"
echo $CLIEXEC
${CLIEXEC}
}
1 year ago
mw_valkey(){
CONF="${ROOT_PATH}/valkey/valkey.conf"
if [ ! -f "$CONF" ]; then
echo -e "not install valkey!"
exit 1
fi
REDISPORT=$(cat $CONF |grep port|grep -v '#'|awk '{print $2}')
REDISPASS=$(cat $CONF |grep requirepass|grep -v '#'|awk '{print $2}')
if [ "$REDISPASS" != "" ];then
REDISPASS=" -a $REDISPASS"
fi
CLIEXEC="${ROOT_PATH}/valkey/bin/valkey-cli -p $REDISPORT$REDISPASS"
echo $CLIEXEC
${CLIEXEC}
}
4 months ago
mw_ssh(){
4 months ago
cd ${PANEL_DIR} && python3 panel_tools.py cli 202
4 months ago
if [[ "$?" == "0" ]]; then
POS=$(echo -e "\n${BLUE}└─ 选择登陆终端:${PLAIN}")
read -p "${POS}" INPUT
SSS=`cd ${PANEL_DIR} && python3 panel_tools.py cli 202 $INPUT`
# echo "info:$SSS"
# SSS="127.0.0.1|22|root|xx"
IFS='|' read -r SERVER_IP SERVER_PORT SERVER_USER SERVER_PASS <<< "$SSS"
4 months ago
echo "Attempting SSH connection to $SERVER_USER@$SERVER_IP:$SERVER_PORT"
4 months ago
sshpass -p "$SERVER_PASS" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -p "$SERVER_PORT" "$SERVER_USER@$SERVER_IP"
4 months ago
fi
4 months ago
}
3 years ago
mw_venv(){
2 years ago
cd ${PANEL_DIR} && source bin/activate
3 years ago
}
3 years ago
mw_clean_lib(){
2 years ago
cd ${PANEL_DIR} && rm -rf lib
cd ${PANEL_DIR} && rm -rf lib64
cd ${PANEL_DIR} && rm -rf bin
cd ${PANEL_DIR} && rm -rf include
3 years ago
}
1 year ago
mw_list(){
1 year ago
echo -e "mw default - 显示面板默认信息"
echo -e "mw db - 连接MySQL"
echo -e "mw pgdb - 连接PostgreSQL"
echo -e "mw mongdb - 连接MongoDB"
echo -e "mw redis - 连接Redis"
echo -e "mw valkey - 连接WalKey"
1 year ago
echo -e "mw install - 执行安装脚本"
1 year ago
echo -e "mw update - 更新到正式环境最新代码"
echo -e "mw update_dev - 更新到测试环境最新代码"
echo -e "mw debug - 调式开发面板"
echo -e "mw list - 显示命令列表"
1 year ago
}
2 years ago
mw_default(){
cd ${PANEL_DIR}
port=7200
1 year ago
scheme=$(cd ${PANEL_DIR} && python3 ${PANEL_DIR}/panel_tools.py panel_ssl_type)
2 years ago
if [ -f ${PANEL_DIR}/data/port.pl ];then
port=$(cat ${PANEL_DIR}/data/port.pl)
fi
2 years ago
if [ ! -f ${PANEL_DIR}/data/default.pl ];then
echo -e "\033[33mInstall Failed\033[0m"
exit 1
fi
2 years ago
password=$(cat ${PANEL_DIR}/data/default.pl)
2 years ago
2 years ago
admin_path=$(cd ${PANEL_DIR} && python3 ${PANEL_DIR}/panel_tools.py admin_path)
2 years ago
if [ "$address" == "" ];then
1 year ago
v4=$(cd ${PANEL_DIR} && python3 ${PANEL_DIR}/panel_tools.py getServerIp 4)
v6=$(cd ${PANEL_DIR} && python3 ${PANEL_DIR}/panel_tools.py getServerIp 6)
2 years ago
if [ "$v4" != "" ] && [ "$v6" != "" ]; then
if [ ! -f ${PANEL_DIR}/data/ipv6.pl ];then
echo 'True' > ${PANEL_DIR}/data/ipv6.pl
mw_stop
mw_start
fi
2 years ago
address="MW-PANEL-URL-IPV4: ${scheme}://$v4:$port$admin_path \nMW-PANEL-URL-IPV6: ${scheme}://[$v6]:$port$admin_path"
2 years ago
elif [ "$v4" != "" ]; then
2 years ago
address="MW-PANEL-URL: ${scheme}://$v4:$port$admin_path"
2 years ago
elif [ "$v6" != "" ]; then
if [ ! -f ${PANEL_DIR}/data/ipv6.pl ];then
# Need to restart ipv6 to take effect
echo 'True' > ${PANEL_DIR}/data/ipv6.pl
mw_stop
mw_start
fi
2 years ago
address="MW-PANEL-URL: ${scheme}://[$v6]:$port$admin_path"
2 years ago
else
2 years ago
address="MW-PANEL-URL: ${scheme}://you-network-ip:$port$admin_path"
2 years ago
fi
else
2 years ago
address="MW-PANEL-URL: ${scheme}://$address:$port$admin_path"
2 years ago
fi
1 year ago
# bind domain check
1 year ago
panel_bind_domain=$(cd ${PANEL_DIR} && python3 ${PANEL_DIR}/panel_tools.py panel_bind_domain)
1 year ago
if [ "$panel_bind_domain" != "" ];then
1 year ago
address="MW-PANEL-URL: ${scheme}://$panel_bind_domain:$port$admin_path\n${address}"
1 year ago
fi
2 years ago
show_panel_ip="$port|"
echo -e "=================================================================="
echo -e "\033[32mMW-PANEL DEFAULT INFO!\033[0m"
echo -e "=================================================================="
echo -e "$address"
1 year ago
echo -e `cd ${PANEL_DIR} && python3 ${PANEL_DIR}/panel_tools.py username`
echo -e `cd ${PANEL_DIR} && python3 ${PANEL_DIR}/panel_tools.py password`
2 years ago
echo -e "\033[33mWarning:\033[0m"
echo -e "\033[33mIf you cannot access the panel. \033[0m"
echo -e "\033[33mrelease the following port (${show_panel_ip}80|443|22) in the security group.\033[0m"
echo -e "=================================================================="
}
8 years ago
case "$1" in
'start') mw_start;;
'stop') mw_stop;;
'reload') mw_reload;;
8 years ago
'restart')
1 month ago
mw_stop
sleep 2
1 month ago
mw_start;;
4 years ago
'restart_panel')
1 month ago
mw_stop_panel
sleep 2
1 month ago
mw_start_panel;;
'restart_task')
1 month ago
mw_stop_task
sleep 2
1 month ago
mw_start_task;;
8 years ago
'status') mw_status;;
'logs') error_logs;;
4 years ago
'close') mw_close;;
'open') mw_open;;
1 year ago
'install') mw_install;;
4 years ago
'update') mw_update;;
2 months ago
'dev') mw_dev;;
4 years ago
'update_dev') mw_update_dev;;
'install_app') mw_install_app;;
4 years ago
'close_admin_path') mw_close_admin_path;;
'unbind_domain') mw_unbind_domain;;
2 years ago
'unbind_ssl') mw_unbind_domain;;
4 years ago
'debug') mw_debug;;
3 years ago
'mirror') mw_mirror;;
3 years ago
'db') mw_connect_mysql;;
2 years ago
'pgdb') mw_connect_pgdb;;
2 years ago
'redis') mw_redis;;
1 year ago
'valkey')mw_valkey;;
2 weeks ago
'mgdb') mw_mongodb;;
2 years ago
'mongodb') mw_mongodb;;
4 months ago
'ssh') mw_ssh;;
2 years ago
'venv') mw_update_venv;;
3 years ago
'clean_lib') mw_clean_lib;;
1 year ago
'list') mw_list;;
2 years ago
'default') mw_default;;
4 years ago
*)
2 years ago
cd ${PANEL_DIR} && python3 ${PANEL_DIR}/panel_tools.py cli $1
4 years ago
;;
4 years ago
esac