-
Notifications
You must be signed in to change notification settings - Fork 114
/
run.sh
executable file
·133 lines (110 loc) · 2.64 KB
/
run.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
#!/bin/sh
NGINX_CONFIG_FILE=/opt/nginx/conf/nginx.conf
RTMP_CONNECTIONS=${RTMP_CONNECTIONS-1024}
RTMP_STREAM_NAMES=${RTMP_STREAM_NAMES-live,testing}
RTMP_STREAMS=$(echo ${RTMP_STREAM_NAMES} | sed "s/,/\n/g")
RTMP_PUSH_URLS=$(echo ${RTMP_PUSH_URLS} | sed "s/,/\n/g")
apply_config() {
echo "Creating config"
## Standard config:
cat >${NGINX_CONFIG_FILE} <<!EOF
worker_processes 1;
events {
worker_connections ${RTMP_CONNECTIONS};
}
!EOF
## HTTP / HLS Config
cat >>${NGINX_CONFIG_FILE} <<!EOF
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2ts ts;
}
root /tmp;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
location /on_publish {
return 201;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
alias /opt/nginx/conf/stat.xsl;
}
location /control {
rtmp_control all;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
!EOF
## RTMP Config
cat >>${NGINX_CONFIG_FILE} <<!EOF
rtmp {
server {
listen 1935;
chunk_size 4096;
!EOF
if [ "x${RTMP_PUSH_URLS}" = "x" ]; then
PUSH="false"
else
PUSH="true"
fi
HLS="true"
for STREAM_NAME in $(echo ${RTMP_STREAMS})
do
echo Creating stream $STREAM_NAME
cat >>${NGINX_CONFIG_FILE} <<!EOF
application ${STREAM_NAME} {
live on;
record off;
on_publish http://localhost:8080/on_publish;
!EOF
if [ "${HLS}" = "true" ]; then
cat >>${NGINX_CONFIG_FILE} <<!EOF
hls on;
hls_path /tmp/hls;
hls_fragment 1;
hls_playlist_length 20;
!EOF
HLS="false"
fi
if [ "$PUSH" = "true" ]; then
for PUSH_URL in $(echo ${RTMP_PUSH_URLS}); do
echo "Pushing stream to ${PUSH_URL}"
cat >>${NGINX_CONFIG_FILE} <<!EOF
push ${PUSH_URL};
!EOF
PUSH=false
done
fi
cat >>${NGINX_CONFIG_FILE} <<!EOF
}
!EOF
done
cat >>${NGINX_CONFIG_FILE} <<!EOF
}
}
!EOF
}
if ! [ -f ${NGINX_CONFIG_FILE} ]; then
apply_config
else
echo "CONFIG EXISTS - Not creating!"
fi
echo "Starting server
/opt/nginx/sbin/nginx -g "daemon off;"