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