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

383 lines
10 KiB

7 years ago
#!/bin/bash
# chkconfig: 2345 55 25
# description: MW Cloud Service
### BEGIN INIT INFO
3 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
4 years ago
PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
2 years ago
export LANG=en_US.UTF-8
7 years ago
mw_path={$SERVER_PATH}
4 years ago
PATH=$PATH:$mw_path/bin
4 years ago
3 years ago
4 years ago
if [ -f $mw_path/bin/activate ];then
source $mw_path/bin/activate
2 years ago
if [ "$?" != "0" ];then
echo "load local python env fail!"
fi
4 years ago
fi
3 years ago
mw_start_panel()
{
isStart=`ps -ef|grep 'gunicorn -c setting.py app:app' |grep -v grep|awk '{print $2}'`
if [ "$isStart" == '' ];then
3 years ago
echo -e "starting mw-panel... \c"
3 years ago
cd $mw_path && gunicorn -c setting.py app:app
port=$(cat ${mw_path}/data/port.pl)
isStart=""
while [[ "$isStart" == "" ]];
do
echo -e ".\c"
sleep 0.5
isStart=$(lsof -n -P -i:$port|grep LISTEN|grep -v grep|awk '{print $2}'|xargs)
let n+=1
if [ $n -gt 60 ];then
3 years ago
break;
7 years ago
fi
3 years ago
done
if [ "$isStart" == '' ];then
3 years ago
echo -e "\033[31mfailed\033[0m"
echo '------------------------------------------------------'
tail -n 20 ${mw_path}/logs/error.log
echo '------------------------------------------------------'
echo -e "\033[31mError: mw-panel service startup failed.\033[0m"
return;
3 years ago
fi
echo -e "\033[32mdone\033[0m"
7 years ago
else
3 years ago
echo "starting mw-panel... mw(pid $(echo $isStart)) already running"
7 years ago
fi
3 years ago
}
7 years ago
3 years ago
mw_start_task()
{
7 years ago
isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" == '' ];then
3 years ago
echo -e "starting mw-tasks... \c"
3 years ago
cd $mw_path && python3 task.py >> ${mw_path}/logs/task.log 2>&1 &
sleep 0.3
isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" == '' ];then
3 years ago
echo -e "\033[31mfailed\033[0m"
echo '------------------------------------------------------'
tail -n 20 $mw_path/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"
7 years ago
else
3 years ago
echo "starting mw-tasks... mw-tasks (pid $(echo $isStart)) already running"
7 years ago
fi
7 years ago
}
3 years ago
mw_start()
{
mw_start_task
3 years ago
mw_start_panel
3 years ago
}
7 years ago
3 years ago
# /www/server/mdserver-web/tmp/panelTask.pl && service mw restart_task
3 years ago
mw_stop_task()
7 years ago
{
if [ -f $mw_path/tmp/panelTask.pl ];then
3 years ago
echo -e "\033[32mthe task is running and cannot be stopped\033[0m"
3 years ago
exit 0
fi
3 years ago
echo -e "stopping mw-tasks... \c";
7 years ago
pids=$(ps aux | 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
7 years ago
done
echo -e "\033[32mdone\033[0m"
3 years ago
}
7 years ago
3 years ago
mw_stop_panel()
{
3 years ago
echo -e "stopping mw-panel... \c";
2 years ago
pidfile=${mw_path}/logs/mw.pid
if [ -f $pidfile ];then
pid=`cat $pidfile`
kill -9 $pid > /dev/null 2>&1
rm -f $pidfile
fi
7 years ago
arr=`ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}'`
3 years ago
for p in ${arr[@]}
7 years ago
do
2 years ago
kill -9 $p > /dev/null 2>&1
7 years ago
done
echo -e "\033[32mdone\033[0m"
}
3 years ago
mw_stop()
{
mw_stop_task
3 years ago
mw_stop_panel
3 years ago
}
7 years ago
mw_status()
{
3 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
isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}')
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
7 years ago
}
mw_reload()
{
isStart=$(ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}')
if [ "$isStart" != '' ];then
3 years ago
echo -e "reload mw... \c";
7 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
6 years ago
cd $mw_path && gunicorn -c setting.py app:app
7 years ago
isStart=`ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}'`
if [ "$isStart" == '' ];then
3 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;
7 years ago
fi
echo -e "\033[32mdone\033[0m"
else
echo -e "\033[31mmw not running\033[0m"
7 years ago
mw_start
7 years ago
fi
}
2 years ago
mw_close(){
echo 'True' > $mw_path/data/close.pl
}
mw_open()
{
if [ -f $mw_path/data/close.pl ];then
rm -rf $mw_path/data/close.pl
fi
}
mw_unbind_domain()
{
if [ -f $mw_path/data/bind_domain.pl ];then
rm -rf $mw_path/data/bind_domain.pl
fi
}
7 years ago
error_logs()
{
tail -n 100 $mw_path/logs/error.log
}
3 years ago
mw_update()
{
2 years ago
LOCAL_ADDR=common
ping -c 1 github.com > /dev/null 2>&1
if [ "$?" != "0" ];then
LOCAL_ADDR=cn
fi
if [ "$LOCAL_ADDR" == "common" ];then
2 years ago
curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/master/scripts/update.sh | bash
2 years ago
else
2 years ago
curl --insecure -fsSL https://code.midoks.me/midoks/mdserver-web/raw/branch/dev/scripts/update.sh | bash
3 years ago
fi
3 years ago
}
mw_update_dev()
{
2 years ago
LOCAL_ADDR=common
ping -c 1 github.com > /dev/null 2>&1
if [ "$?" != "0" ];then
LOCAL_ADDR=cn
fi
if [ "$LOCAL_ADDR" == "common" ];then
2 years ago
curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh | bash
2 years ago
else
2 years ago
curl --insecure -fsSL https://code.midoks.me/midoks/mdserver-web/raw/branch/dev/scripts/update_dev.sh | bash
3 years ago
fi
3 years ago
cd /www/server/mdserver-web
3 years ago
}
mw_mirror()
{
2 years ago
LOCAL_ADDR=common
ping -c 1 github.com > /dev/null 2>&1
if [ "$?" != "0" ];then
LOCAL_ADDR=cn
fi
if [ "$LOCAL_ADDR" == "common" ];then
2 years ago
bash <(curl --insecure -sSL https://raw.githubusercontent.com/midoks/change-linux-mirrors/main/change-mirrors.sh)
2 years ago
else
bash <(curl --insecure -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)
fi
cd /www/server/mdserver-web
}
mw_install_app()
{
bash $mw_path/scripts/quick/app.sh
}
3 years ago
mw_close_admin_path(){
if [ -f $mw_path/data/admin_path.pl ]; then
rm -rf $mw_path/data/admin_path.pl
fi
}
3 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
}
3 years ago
mw_debug(){
3 years ago
mw_stop
3 years ago
mw_force_kill
3 years ago
port=7200
if [ -f $mw_path/data/port.pl ];then
port=$(cat $mw_path/data/port.pl)
fi
3 years ago
3 years ago
if [ -d /www/server/mdserver-web ];then
cd /www/server/mdserver-web
fi
3 years ago
gunicorn -b :$port -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
}
7 years ago
case "$1" in
'start') mw_start;;
'stop') mw_stop;;
'reload') mw_reload;;
7 years ago
'restart')
mw_stop
mw_start;;
3 years ago
'restart_panel')
mw_stop_panel
mw_start_panel;;
'restart_task')
mw_stop_task
mw_start_task;;
7 years ago
'status') mw_status;;
'logs') error_logs;;
2 years ago
'close') mw_close;;
'open') mw_open;;
3 years ago
'update') mw_update;;
'update_dev') mw_update_dev;;
'install_app') mw_install_app;;
3 years ago
'close_admin_path') mw_close_admin_path;;
'unbind_domain') mw_unbind_domain;;
3 years ago
'debug') mw_debug;;
2 years ago
'mirror') mw_mirror;;
6 years ago
'default')
cd $mw_path
3 years ago
port=7200
if [ -f $mw_path/data/port.pl ];then
port=$(cat $mw_path/data/port.pl)
fi
3 years ago
if [ ! -f $mw_path/data/default.pl ];then
echo -e "\033[33mInstall Failed\033[0m"
3 years ago
exit 1
3 years ago
fi
6 years ago
password=$(cat $mw_path/data/default.pl)
if [ -f $mw_path/data/domain.conf ];then
address=$(cat $mw_path/data/domain.conf)
fi
if [ -f $mw_path/data/admin_path.pl ];then
auth_path=$(cat $mw_path/data/admin_path.pl)
fi
3 years ago
2 years ago
if [ "$address" == "" ];then
3 years ago
v4=$(python3 $mw_path/tools.py getServerIp 4)
v6=$(python3 $mw_path/tools.py getServerIp 6)
3 years ago
if [ "$v4" != "" ] && [ "$v6" != "" ]; then
2 years ago
if [ ! -f $mw_path/data/ipv6.pl ];then
echo 'True' > $mw_path/data/ipv6.pl
mw_stop
mw_start
fi
3 years ago
address="MW-Panel-Url-Ipv4: http://$v4:$port$auth_path \nMW-Panel-Url-Ipv6: http://[$v6]:$port$auth_path"
3 years ago
elif [ "$v4" != "" ]; then
3 years ago
address="MW-Panel-Url: http://$v4:$port$auth_path"
3 years ago
elif [ "$v6" != "" ]; then
3 years ago
if [ ! -f $mw_path/data/ipv6.pl ];then
3 years ago
# Need to restart ipv6 to take effect
2 years ago
echo 'True' > $mw_path/data/ipv6.pl
3 years ago
mw_stop
mw_start
fi
3 years ago
address="MW-Panel-Url: http://[$v6]:$port$auth_path"
3 years ago
else
3 years ago
address="MW-Panel-Url: http://you-network-ip:$port$auth_path"
3 years ago
fi
else
3 years ago
address="MW-Panel-Url: http://$address:$port$auth_path"
3 years ago
fi
3 years ago
3 years ago
show_panel_ip="$port|"
6 years ago
echo -e "=================================================================="
echo -e "\033[32mMW-Panel default info!\033[0m"
echo -e "=================================================================="
3 years ago
echo -e "$address"
4 years ago
echo -e `python3 $mw_path/tools.py username`
2 years ago
echo -e `python3 $mw_path/tools.py password`
# echo -e "password: $password"
6 years ago
echo -e "\033[33mWarning:\033[0m"
3 years ago
echo -e "\033[33mIf you cannot access the panel. \033[0m"
2 years ago
echo -e "\033[33mrelease the following port (${show_panel_ip}|80|443|22) in the security group.\033[0m"
6 years ago
echo -e "=================================================================="
;;
3 years ago
*)
cd $mw_path && python3 $mw_path/tools.py cli $1
;;
3 years ago
esac