Skip to content

Commit

Permalink
feat: support log rotate for srs log with compress and cron
Browse files Browse the repository at this point in the history
  • Loading branch information
peipeiguo committed Jul 11, 2022
1 parent 76d7aef commit 1aea46c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion trunk/Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ RUN echo "BUILDPLATFORM: $BUILDPLATFORM, TARGETPLATFORM: $TARGETPLATFORM"
# Expose ports for streaming @see https://github.com/ossrs/srs#ports
EXPOSE 1935 1985 8080 8000/udp 10080/udp

# For SRS Log Rotate
ARG DEBIAN_FRONTEND=noninteractive
ARG DEBCONF_NOWARNINGS="yes"
RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests cron logrotate
COPY trunk/scripts/start.sh /usr/local/srs/

# FFMPEG 4.1
COPY --from=build /usr/local/bin/ffmpeg /usr/local/srs/objs/ffmpeg/bin/ffmpeg
# SRS binary, config files and srs-console.
COPY --from=build /usr/local/srs /usr/local/srs

# Default workdir and command.
WORKDIR /usr/local/srs
CMD ["./objs/srs", "-c", "conf/docker.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 7
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 1aea46c

Please sign in to comment.