forked from Thiritin/streaming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
347 lines (295 loc) · 11 KB
/
Copy pathinstall.sh
File metadata and controls
347 lines (295 loc) · 11 KB
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# EF Streaming Edge Server Installation Script
# Generated: 2025-08-31 18:55:53
# Server ID: 10
# Hostname: edge-10-Ur16YGLgHK2J.stream.eurofurence.org
set -e
echo "================================================"
echo "EF Streaming Server Installation"
echo "Server Type: edge"
echo "Generated: 2025-08-31 18:55:53"
echo "================================================"
# Update system
apt-get update
apt-get upgrade -y
# Install Docker
if ! command -v docker &> /dev/null; then
echo "Installing Docker..."
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
rm get-docker.sh
else
echo "Docker already installed"
fi
# Install Docker Compose
if ! command -v docker-compose &> /dev/null; then
echo "Installing Docker Compose..."
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
else
echo "Docker Compose already installed"
fi
# Create working directory
mkdir -p /opt/ef-streaming
cd /opt/ef-streaming
# Create environment file
cat > .env <<EOF
SERVER_ID=10
SERVER_TYPE=edge
SHARED_SECRET=2rf93eFTm1dmlxRwDVyfGgkk5QYxVixG7TUW3JLK
APP_URL=https://well-oarfish-oddly.ngrok-free.app
# DVR S3 Storage Configuration
DVR_AWS_ACCESS_KEY_ID=
DVR_AWS_SECRET_ACCESS_KEY=
DVR_AWS_DEFAULT_REGION=eu-west-1
DVR_AWS_BUCKET=streaming-dvr
DVR_AWS_ENDPOINT=https://s3.eurofurence.org
EOF
# Download Edge Docker Compose configuration
cat > docker-compose.yml <<'DOCKERCOMPOSE'
version: '3.8'
services:
# Edge Nginx - Caching proxy for HLS content
edge-nginx:
image: nginx:alpine
container_name: edge-nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
tmpfs:
- /var/cache/nginx:rw,noexec,nosuid,size=512m
restart: unless-stopped
networks:
- streaming
# Edge Caddy - SSL termination for edge
edge-caddy:
image: caddy:alpine
container_name: edge-caddy
ports:
- "80:80"
- "443:443"
environment:
DOMAIN: edge-10-Ur16YGLgHK2J.stream.eurofurence.org
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy-data:/data
- caddy-config:/config
restart: unless-stopped
depends_on:
- edge-nginx
networks:
- streaming
networks:
streaming:
driver: bridge
volumes:
caddy-data:
caddy-config:DOCKERCOMPOSE
# Create Edge Nginx configuration
cat > nginx.conf <<'NGINXCONF'
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 4096;
use epoll;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# Gzip compression
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml text/javascript
application/json application/javascript application/xml+rss
application/vnd.apple.mpegurl video/mp2t;
# Rate limiting
limit_req_zone $binary_remote_addr zone=viewer_limit:10m rate=30r/s;
limit_conn_zone $binary_remote_addr zone=viewer_conn:10m;
# Cache paths for different content types - optimized for quality switching
proxy_cache_path /var/cache/nginx/auth levels=1:2 keys_zone=auth_cache:10m
max_size=100m inactive=10s use_temp_path=off;
proxy_cache_path /var/cache/nginx/hls levels=1:2 keys_zone=hls_cache:10m
max_size=100m inactive=2s use_temp_path=off;
proxy_cache_path /var/cache/nginx/segments levels=1:2 keys_zone=segment_cache:100m
max_size=2g inactive=1h use_temp_path=off
loader_files=200 loader_sleep=50ms loader_threshold=300ms;
# Upstream for origin Caddy server
upstream origin_caddy {
server origin-8-1Fn5B9fkKSmO.stream.eurofurence.org:8070;
keepalive 32;
}
server {
listen 80;
listen [::]:80;
server_name _;
# Rate limiting
limit_req zone=viewer_limit burst=50 nodelay;
limit_conn viewer_conn 10;
# Health check endpoint
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
# Authentication subrequest endpoint
location = /auth {
internal;
proxy_pass http://well-oarfish-oddly.ngrok-free.app:443/api/hls/auth;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Edge-Server "edge-nginx";
# Pass streamkey as header for authentication
proxy_set_header X-Stream-Key $arg_streamkey;
# Cache auth responses for performance
proxy_cache auth_cache;
proxy_cache_key "$remote_addr:$arg_streamkey:$uri";
proxy_cache_valid 200 10s;
proxy_cache_valid 401 403 1s;
}
# HLS m3u8 playlist files - proxy and cache from origin
location ~ ^/live/(.+\.m3u8)$ {
# Proxy to origin Caddy server
proxy_pass http://origin_caddy$request_uri;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Connection "";
# Cache configuration for m3u8 playlists
proxy_cache hls_cache;
# Cache key uses URI without query parameters
proxy_cache_key "$scheme$proxy_host$uri";
proxy_cache_valid 200 2s;
proxy_cache_valid 404 1s;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_lock on;
proxy_cache_lock_timeout 5s;
# CORS headers
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, HEAD, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length, Content-Range' always;
# Add cache status header for debugging
add_header X-Cache-Status $upstream_cache_status;
# HLS headers
add_header Content-Type "application/vnd.apple.mpegurl";
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header X-Content-Type-Options "nosniff";
}
# TS segment files - proxy and cache from origin
location ~ ^/live/(.+\.ts)$ {
# Perform authentication check
auth_request /auth;
auth_request_set $auth_status $upstream_status;
# Proxy to origin Caddy server
proxy_pass http://origin_caddy$request_uri;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Connection "";
# Cache configuration for TS segments
proxy_cache segment_cache;
# Cache key uses URI without query parameters
proxy_cache_key "$scheme$proxy_host$uri";
proxy_cache_valid 200 5m;
proxy_cache_valid 404 10s;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_lock on;
proxy_cache_lock_timeout 5s;
# CORS headers
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, HEAD, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length, Content-Range' always;
# Add cache status header for debugging
add_header X-Cache-Status $upstream_cache_status;
# Cache headers for CDN and browsers
expires 5m;
add_header Cache-Control "public, max-age=300, immutable";
add_header Content-Type "video/mp2t";
add_header X-Content-Type-Options "nosniff";
}
# Default location
location / {
return 404;
}
}
}NGINXCONF
# Create Edge Caddy configuration
cat > Caddyfile <<'CADDYFILE'
edge-10-Ur16YGLgHK2J.stream.eurofurence.org {
reverse_proxy edge-nginx:80
}CADDYFILE
# Start services
echo "Starting Docker services..."
docker compose up -d
# Wait for services to be ready
echo "Waiting for services to start..."
WAITED=0
MAX_WAIT=60
while [ $WAITED -lt $MAX_WAIT ]; do
if [ "edge" = "origin" ]; then
# For origin, check if SRS is responding
if curl -s http://localhost:1985/api/v1/versions > /dev/null 2>&1; then
echo "Origin services are ready!"
break
fi
else
# For edge, check if nginx is responding
if curl -s http://localhost:8081/health > /dev/null 2>&1; then
echo "Edge services are ready!"
break
fi
fi
echo "Waiting for services... ($WAITED/$MAX_WAIT seconds)"
sleep 5
WAITED=$((WAITED + 5))
done
# Show service status
docker compose ps
# Get server information
# Force IPv4 for PUBLIC_IP and use the configured hostname
PUBLIC_IP=$(curl -4 -s ifconfig.me)
HOSTNAME="edge-10-Ur16YGLgHK2J.stream.eurofurence.org"
echo "================================================"
echo "Server Information:"
echo " Public IP: $PUBLIC_IP"
echo " Hostname: $HOSTNAME"
echo " Server Type: edge"
echo " Server ID: 10"
echo "================================================"
# Register server with main app (optional - may fail if network not ready)
echo "Attempting to register server with main application..."
curl -L -X POST "https://well-oarfish-oddly.ngrok-free.app/api/server/register" \
-H "X-Shared-Secret: 2rf93eFTm1dmlxRwDVyfGgkk5QYxVixG7TUW3JLK" \
-H "Content-Type: application/json" \
-d "{
\"server_id\": \"10\",
\"hostname\": \"$HOSTNAME\",
\"ip\": \"$PUBLIC_IP\",
\"status\": \"active\"
}" || echo "Registration failed - server will register on first heartbeat"
echo "================================================"
echo "Installation complete!"
echo "Server is ready at: $PUBLIC_IP"
echo "================================================"
# Setup auto-restart on boot
systemctl enable docker
# Setup heartbeat cron job (every minute)
(crontab -l 2>/dev/null; echo "* * * * * /opt/ef-streaming/heartbeat.sh") | crontab -
exit 0