Skip to content

Commit

Permalink
Support log rotate for srs with compress and start cron
Browse files Browse the repository at this point in the history
  • Loading branch information
peipeiguo committed May 17, 2022
1 parent e4242b5 commit 4fe423c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
12 changes: 11 additions & 1 deletion trunk/Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ FROM ubuntu:focal-20210609 AS dist
# RTMP/1935, API/1985, HTTP/8080
EXPOSE 1935 1985 8080 8000 10080

# For SRS Log Rotate
ARG DEBIAN_FRONTEND=noninteractive
ARG DEBCONF_NOWARNINGS="yes"
RUN apt-get update
RUN apt-get install -y --no-install-recommends --no-install-suggests cron logrotate

RUN mkdir -p /usr/local/srs/objs
#ADD objs/nginx /usr/local/srs/objs/nginx
COPY research/api-server/static-dir/index.html /usr/local/srs/objs/nginx/html/
Expand All @@ -21,5 +27,9 @@ COPY objs/srs /usr/local/srs/objs/
# Use docker.conf as default config.
#COPY conf /usr/local/srs/conf
# Default workdir and command.

# Add script for starting SRS with logrotate
COPY scripts/start.sh /usr/local/srs/

WORKDIR /usr/local/srs
CMD ["./objs/srs", "-c", "conf/bruce.conf"]
ENTRYPOINT ["/usr/local/srs/start.sh"]
26 changes: 26 additions & 0 deletions trunk/scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# create logrotate config for srs log
SRS_LOG_FILE=`grep srs_log_file /usr/local/srs/conf/bruce.conf | awk '{print $NF}' | cut -d ';' -f 1`
cat > /etc/logrotate.d/srs << EOF
$SRS_LOG_FILE {
daily
dateext
dateformat -%Y-%m-%d.log
compress
delaycompress
missingok
rotate 15
sharedscripts
postrotate
if [ -f /usr/local/srs/objs/srs.pid ]; then
kill -USR1 \`cat /usr/local/srs/objs/srs.pid\`
fi
endscript
}
EOF

# start cron for logrotate
service cron start

# start srs
/usr/local/srs/objs/srs -c conf/bruce.conf

0 comments on commit 4fe423c

Please sign in to comment.