|
| 1 | +#!/bin/bash |
| 2 | +# chkconfig: 2345 55 25 |
| 3 | +# description: bt Cloud Service |
| 4 | + |
| 5 | +### BEGIN INIT INFO |
| 6 | +# Provides: bt |
| 7 | +# Required-Start: $all |
| 8 | +# Required-Stop: $all |
| 9 | +# Default-Start: 2 3 4 5 |
| 10 | +# Default-Stop: 0 1 6 |
| 11 | +# Short-Description: starts bt |
| 12 | +# Description: starts the bt |
| 13 | +### END INIT INFO |
| 14 | +panel_path=/www/server/panel |
| 15 | +cd $panel_path |
| 16 | +panel_start() |
| 17 | +{ |
| 18 | + isStart=`ps aux |grep 'python main.pyc'|grep -v grep|awk '{print $2}'` |
| 19 | + if [ "$isStart" == '' ];then |
| 20 | + echo -e "Starting Bt-Panel... \c" |
| 21 | + if [ -f 'main.py' ];then |
| 22 | + python -m py_compile main.py |
| 23 | + fi |
| 24 | + nohup python main.pyc `cat data/port.pl` > /tmp/panelBoot.pl 2>&1 & |
| 25 | + sleep 0.2 |
| 26 | + isStart=`ps aux |grep 'python main.pyc'|grep -v grep|awk '{print $2}'` |
| 27 | + if [ "$isStart" == '' ];then |
| 28 | + echo -e "\033[31mfailed\033[0m" |
| 29 | + echo '------------------------------------------------------' |
| 30 | + cat /tmp/panelBoot.pl |
| 31 | + echo '------------------------------------------------------' |
| 32 | + echo -e "\033[31mError: BT-Panel service startup failed.\033[0m" |
| 33 | + return; |
| 34 | + fi |
| 35 | + echo -e "\033[32mdone\033[0m" |
| 36 | + else |
| 37 | + echo "Starting Bt-Panel... Bt-Panel (pid $isStart) already running" |
| 38 | + fi |
| 39 | + |
| 40 | + isStart=`ps aux |grep 'python task.pyc$'|awk '{print $2}'` |
| 41 | + if [ "$isStart" == '' ];then |
| 42 | + echo -e "Starting Bt-Tasks... \c" |
| 43 | + if [ -f 'task.py' ];then |
| 44 | + python -m py_compile task.py |
| 45 | + fi |
| 46 | + nohup python task.pyc > /tmp/panelTask.pl 2>&1 & |
| 47 | + sleep 0.2 |
| 48 | + isStart=`ps aux |grep 'python task.pyc$'|awk '{print $2}'` |
| 49 | + if [ "$isStart" == '' ];then |
| 50 | + echo -e "\033[31mfailed\033[0m" |
| 51 | + echo '------------------------------------------------------' |
| 52 | + cat /tmp/panelTask.pl |
| 53 | + echo '------------------------------------------------------' |
| 54 | + echo -e "\033[31mError: BT-Task service startup failed.\033[0m" |
| 55 | + return; |
| 56 | + fi |
| 57 | + echo -e "\033[32mdone\033[0m" |
| 58 | + else |
| 59 | + echo "Starting Bt-Tasks... Bt-Tasks (pid $isStart) already running" |
| 60 | + fi |
| 61 | +} |
| 62 | + |
| 63 | +panel_stop() |
| 64 | +{ |
| 65 | + echo -e "Stopping Bt-Tasks... \c"; |
| 66 | + pids=`ps aux | grep 'python task.pyc$'|awk '{print $2}'` |
| 67 | + arr=($pids) |
| 68 | + |
| 69 | + for p in ${arr[@]} |
| 70 | + do |
| 71 | + kill -9 $p |
| 72 | + done |
| 73 | + echo -e "\033[32mdone\033[0m" |
| 74 | + |
| 75 | + echo -e "Stopping Bt-Panel... \c"; |
| 76 | + pids=`ps aux | grep 'python main.pyc'|grep -v grep|awk '{print $2}'` |
| 77 | + arr=($pids) |
| 78 | + |
| 79 | + for p in ${arr[@]} |
| 80 | + do |
| 81 | + kill -9 $p |
| 82 | + done |
| 83 | + echo -e "\033[32mdone\033[0m" |
| 84 | +} |
| 85 | + |
| 86 | +panel_status() |
| 87 | +{ |
| 88 | + isStart=`ps aux |grep 'python main.pyc'|grep -v grep|awk '{print $2}'` |
| 89 | + if [ "$isStart" != '' ];then |
| 90 | + echo -e "\033[32mBt-Panel (pid $isStart) already running\033[0m" |
| 91 | + else |
| 92 | + echo -e "\033[31mBt-Panel not running\033[0m" |
| 93 | + fi |
| 94 | + |
| 95 | + isStart=`ps aux |grep 'python task.pyc$'|awk '{print $2}'` |
| 96 | + if [ "$isStart" != '' ];then |
| 97 | + echo -e "\033[32mBt-Task (pid $isStart) already running\033[0m" |
| 98 | + else |
| 99 | + echo -e "\033[31mBt-Task not running\033[0m" |
| 100 | + fi |
| 101 | +} |
| 102 | + |
| 103 | +panel_reload() |
| 104 | +{ |
| 105 | + isStart=`ps aux |grep 'python main.pyc'|grep -v grep|awk '{print $2}'` |
| 106 | + if [ "$isStart" != '' ];then |
| 107 | + echo -e "Reload service Bt-Panel... \c" |
| 108 | + pids=`ps aux | grep 'python main.pyc'|grep -v grep|awk '{print $2}'` |
| 109 | + arr=($pids) |
| 110 | + for p in ${arr[@]} |
| 111 | + do |
| 112 | + kill -9 $p |
| 113 | + done |
| 114 | + nohup python main.pyc `cat data/port.pl` >> /tmp/panelBoot.pl 2>&1 & |
| 115 | + if [ "$isStart" == '' ];then |
| 116 | + echo -e "\033[31mfailed\033[0m" |
| 117 | + echo '------------------------------------------------------' |
| 118 | + cat /tmp/panelBoot.pl |
| 119 | + echo '------------------------------------------------------' |
| 120 | + echo -e "\033[31mError: BT-Panel service startup failed.\033[0m" |
| 121 | + return; |
| 122 | + fi |
| 123 | + echo -e "\033[32mdone\033[0m" |
| 124 | + else |
| 125 | + echo -e "\033[31mBt-Panel not running\033[0m" |
| 126 | + fi |
| 127 | +} |
| 128 | + |
| 129 | +install_used() |
| 130 | +{ |
| 131 | + if [ ! -f /www/server/panel/aliyun.pl ];then |
| 132 | + return; |
| 133 | + fi |
| 134 | + password=`cat /dev/urandom | head -n 16 | md5sum | head -c 12` |
| 135 | + username=`python /www/server/panel/tools.py panel $password` |
| 136 | + echo "$password" > /www/server/panel/default.pl |
| 137 | + rm -f /www/server/panel/aliyun.pl |
| 138 | +} |
| 139 | + |
| 140 | + |
| 141 | +case "$1" in |
| 142 | + 'start') |
| 143 | + install_used |
| 144 | + panel_start |
| 145 | + ;; |
| 146 | + 'stop') |
| 147 | + panel_stop |
| 148 | + ;; |
| 149 | + 'restart') |
| 150 | + panel_stop |
| 151 | + sleep 0.2 |
| 152 | + panel_start |
| 153 | + ;; |
| 154 | + 'reload') |
| 155 | + panel_reload |
| 156 | + ;; |
| 157 | + 'status') |
| 158 | + panel_status |
| 159 | + ;; |
| 160 | + 'default') |
| 161 | + port=`cat /www/server/panel/data/port.pl` |
| 162 | + password=`cat /www/server/panel/default.pl` |
| 163 | + echo -e "==================================================================" |
| 164 | + echo -e "\033[32mBT-Panel default info!\033[0m" |
| 165 | + echo -e "==================================================================" |
| 166 | + echo "Bt-Panel: http://IP:$port" |
| 167 | + echo -e "username: admin" |
| 168 | + echo -e "password: $password" |
| 169 | + echo -e "\033[33mWarning:\033[0m" |
| 170 | + echo -e "\033[33mIf you cannot access the panel, \033[0m" |
| 171 | + echo -e "\033[33mrelease the following port (8888|888|80|443|20|21) in the security group\033[0m" |
| 172 | + echo -e "==================================================================" |
| 173 | + ;; |
| 174 | + *) |
| 175 | + echo "Usage: /etc/init.d/bt {start|stop|restart|reload|default}" |
| 176 | + ;; |
| 177 | +esac |
0 commit comments