-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
deploy_smart_rtmpd.sh
332 lines (286 loc) · 10.2 KB
/
deploy_smart_rtmpd.sh
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
red='\e[0;41m' # 红色
RED='\e[1;31m'
green='\e[0;32m' # 绿色
GREEN='\e[1;32m'
yellow='\e[5;43m' # 黄色
YELLOW='\e[1;33m'
blue='\e[0;34m' # 蓝色
BLUE='\e[1;34m'
purple='\e[0;35m' # 紫色
PURPLE='\e[1;35m'
cyan='\e[4;36m' # 蓝绿色
CYAN='\e[1;36m'
WHITE='\e[1;37m' # 白色
NC='\e[0m' # 没有颜色
app_name=smart_rtmpd
#############################################################
#
# Wellcom ( 欢迎词 )
#
#############################################################
title=$(cat<<EOF
${CYAN}
:'######::'##::::'##::::'###::::'########::'########::::'########::'########:'##::::'##:'########::'########::
'##... ##: ###::'###:::'## ##::: ##.... ##:... ##..::::: ##.... ##:... ##..:: ###::'###: ##.... ##: ##.... ##:
##:::..:: ####'####::'##:. ##:: ##:::: ##:::: ##::::::: ##:::: ##:::: ##:::: ####'####: ##:::: ##: ##:::: ##:
. ######:: ## ### ##:'##:::. ##: ########::::: ##::::::: ########::::: ##:::: ## ### ##: ########:: ##:::: ##:
:..... ##: ##. #: ##: #########: ##.. ##:::::: ##::::::: ##.. ##:::::: ##:::: ##. #: ##: ##.....::: ##:::: ##:
'##::: ##: ##:.:: ##: ##.... ##: ##::. ##::::: ##::::::: ##::. ##::::: ##:::: ##:.:: ##: ##:::::::: ##:::: ##:
. ######:: ##:::: ##: ##:::: ##: ##:::. ##:::: ##::::::: ##:::. ##:::: ##:::: ##:::: ##: ##:::::::: ########::
:......:::..:::::..::..:::::..::..:::::..:::::..::::::::..:::::..:::::..:::::..:::::..::..:::::::::........:::
${NC}
EOF
)
brief=$(cat<<EOF
${YELLOW}
/**************************************************************************************************
* *
* Copyright (C) 2024 www.qiyicc.com All rights reserved. *
* *
* @file deploy_smart_rtmpd *
* @brief 一键部署 smart_rtmpd 流媒体服务器 *
* Details. *
* *
* @author FreeABC *
* @email cwf12345@sina.com *
* @QQ 99766553 *
* @WebChat 99766553 *
* @github https://github.com/superconvert/smart_rtmpd *
* @gitee https://gitee.com/superconvert/smart_rtmpd *
* @webadmin https://github.com/superconvert/smart_rtmpd/blob/master/web%20manager/src/README.md *
* @version 0.1 *
* @date 2024-07-08 *
* *
*-------------------------------------------------------------------------------------------------*
* Remark : Description *
*-------------------------------------------------------------------------------------------------*
* Change History : *
* <Date> | <Version> | <Author> | <Description> *
*-------------------------------------------------------------------------------------------------*
* 2024-07-08 | 0.1.0 | FreeABC | 新建文件 *
*-------------------------------------------------------------------------------------------------*
* *
**************************************************************************************************/
${NC}
EOF
)
echo -e "${title}"
echo -e "${brief}"
#############################################################
#
# env check ( 环境检测 )
#
#############################################################
OS_TYPE=/etc/redhat-release
# 端口检测
function env_port() {
echo ""
echo -e "${YELLOW}端口检测 ...${NC}"
rtmp=$(ss -lnp | grep 1935)
http=$(ss -lnp | grep 8080)
https=$(ss -lnp | grep 8181)
rtsp=$(ss -lnp | grep 8554)
srt=$(ss -lnp | grep 9000)
sip=$(ss -lnp | grep 5060)
ims=$(ss -lnp | grep 6666)
if [[ ${rtmp} ]]; then
printf "${RED}rtmp port 被占用${NC}\n"
exit
else
printf "${GREEN}rtmp port 正常${NC}\n"
fi
if [[ ${http} ]]; then
printf "${RED}http port 被占用${NC}\n"
exit
else
printf "${GREEN}http port 正常${NC}\n"
fi
if [[ ${https} ]]; then
printf "${RED}https port 被占用${NC}\n"
exit
else
printf "${GREEN}https port 正常${NC}\n"
fi
if [[ ${rtsp} ]]; then
printf "${RED}rtsp port 被占用${NC}\n"
exit
else
printf "${GREEN}rtsp port 正常${NC}\n"
fi
if [[ ${srt} ]]; then
printf "${RED}srt port 被占用${NC}\n"
exit
else
printf "${GREEN}srt port 正常${NC}\n"
fi
if [[ ${sip} ]]; then
printf "${RED}sip port 被占用${NC}\n"
exit
else
printf "${GREEN}sip port 正常${NC}\n"
fi
if [[ ${ims} ]]; then
printf "${RED}ims port 被占用${NC}\n"
exit
else
printf "${GREEN}ims port 正常${NC}\n"
fi
}
# rpm 包是否存在,不存在则初始化环境
function env_rpm(){
rpm_name=$1
var_rpm=$(rpm -qa | grep ${rpm_name})
if [[ $? -ne 0 || ! -n "${var_rpm}" ]]; then
yum -y install ${rpm_name}
if [[ $? -eq 0 ]]; then
printf "${CYAN}%-16s : ok${NC}\n" ${rpm_name}
else
printf "${RED}%-16s : failed${NC}\n" ${rpm_name}
exit
fi
else
printf "${CYAN}%-16s : ok${NC}\n" ${rpm_name}
fi
}
# deb 包是否存在,不存在则初始化环境
function env_deb(){
deb_name=$1
var_deb=$(dpkg -l | grep ${deb_name})
if [[ $? -ne 0 || ! -n "${var_deb}" ]]; then
apt -y install ${deb_name}
if [[ $? -eq 0 ]]; then
printf "${CYAN}%-16s : ok${NC}\n" ${deb_name}
else
printf "${RED}%-16s : failed${NC}\n" ${deb_name}
exit
fi
else
printf "${CYAN}%-16s : ok${NC}\n" ${deb_name}
fi
}
############################################################
#
# download ( 下载软件包 )
#
############################################################
function download(){
echo ""
echo -e "${YELLOW}下载软件包 ...${NC}"
os_name=$1
rm tmp -rf && mkdir tmp && cd tmp
curl -o smart_rtmpd.zip http://www.qiyicc.com/download/rtmpd.zip
echo ""
echo -e "${YELLOW}正在部署环境 ...${NC}"
unzip smart_rtmpd.zip
if [ ${os_name} = 'ubuntu' ]; then
bin_name=smart_rtmpd.multithread.ubuntu16.04LTS.x64.tar.gz
else
bin_name=smart_rtmpd.multithread.centos7.7.1908.x64.tar.gz
fi
mv rtmpd/${bin_name} ./
rm smart_rtmpd.zip rtmpd -rf
mkdir smart_rtmpd
tar zxf ${bin_name} -C smart_rtmpd
rm ${bin_name} -rf
rm /opt/smart_rtmpd -rf
mv smart_rtmpd /opt/
cd ..
rm tmp -rf
}
############################################################
#
# run_server (准备运行环境)
#
############################################################
cat > start_rtmpd.sh << 'EOF'
#!/bin/sh
cd /opt/smart_rtmpd/
nohup ./run_rtmpd.sh > /dev/null 2>&1 &
EOF
cat > stop_rtmpd.sh << 'EOF'
#!/bin/sh
# 停止监听进程
server=`ps aux | grep ./run_rtmpd.sh | grep -v grep | awk -F ' ' '{print $2}'`
if [ "$server" ]; then
kill -9 $server
fi
# 停止流媒体服务器 smart_rtmpd
server=`ps aux | grep ./smart_rtmpd | grep -v grep | awk -F ' ' '{print $2}'`
if [ "$server" ]; then
kill -9 $server
fi
EOF
cat > run_rtmpd.sh << 'EOF'
#!/bin/sh
cd /opt/smart_rtmpd
# 添加本地执行路径
export LD_LIBRARY_PATH=./
while true; do
# 启动一个循环,定时检查进程是否存在
server=`ps aux | grep ./smart_rtmpd | grep -v grep`
if [ ! "$server" ]; then
# 如果不存在就重新启动
./smart_rtmpd -d
sleep 5
fi
sleep 3
done
EOF
function runserver(){
echo ""
echo -e "${YELLOW}准备启动 smart rtmpd 流媒体服务器 ...${NC}"
chmod +x start_rtmpd.sh && mv start_rtmpd.sh /opt/smart_rtmpd/
chmod +x run_rtmpd.sh && mv run_rtmpd.sh /opt/smart_rtmpd/
chmod +x stop_rtmpd.sh && mv stop_rtmpd.sh /opt/smart_rtmpd/
/opt/smart_rtmpd/start_rtmpd.sh
i=0
while [ $i -le 6 ]
do
let i++
sleep 1
echo -e "${CYAN}please waiting.${NC}"
done
state=$(ss -lnp | grep 1935)
if [[ ${state} ]]; then
printf "${GREEN}启动成功!!!${NC}\n"
else
printf "${RED}启动失败!!!${NC}\n"
fi
echo -e "${PURPLE}您的服务器工作目录是: /opt/smart_rtmpd ${NC}"
echo -e "${PURPLE}您的服务器启动脚本是: /opt/smart_rtmpd/start_rtmpd.sh ${NC}"
echo -e "${PURPLE}您的服务器停止脚本是: /opt/smart_rtmpd/stop_rtmpd.sh ${NC}"
}
############################################################
#
# 主函数 ( CentOS )
#
############################################################
function deploy_centos() {
echo -e "${YELLOW}基本环境检测 ...${NC}"
env_rpm tar
env_rpm unzip
env_port
download centos
runserver
}
############################################################
#
# 主函数 ( Ubuntu )
#
############################################################
function deploy_ubuntu() {
echo -e "${YELLOW}基本环境检测 ...${NC}"
env_deb tar
env_deb unzip
env_port
download ubuntu
runserver
}
if [ -f "$OS_TYPE" ];then
if [[ `cat /etc/redhat-release` =~ $C ]];then
deploy_centos
exit
fi
fi
deploy_ubuntu