Skip to content

Commit

Permalink
feat: add logrotate support
Browse files Browse the repository at this point in the history
  • Loading branch information
WGrape committed Feb 18, 2023
1 parent 2800539 commit a01b372
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,22 @@ FROM --platform=linux/amd64 openresty/openresty:1.21.4.1-4-centos7
# not ENV TZ "Asia/Shanghai"
ENV TZ Asia/Shanghai

# configure the mirror of yum.
# https://mirrors.163.com/.help/centos.html
RUN wget https://mirrors.163.com/.help/CentOS7-Base-163.repo \
&& mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup \
&& mv CentOS7-Base-163.repo /etc/yum.repos.d/CentOS7-Base-163.repo \
&& yum clean all && yum makecache

# install the crontab and logrotate for log rotating.
RUN yum -y install logrotate crontabs

# add logrotate to crontab
COPY ./conf/logrotate/logrotate.conf /etc/logrotate.d
RUN echo "0 0 * * * /etc/cron.daily/logrotate" >> mycrontab \
&& crontab mycrontab \
&& rm mycrontab


WORKDIR /dist
COPY . /dist/
23 changes: 23 additions & 0 deletions conf/logrotate/logrotate.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/dist/logs/ngxway.access.log {
su root root
daily
compress
rotate 7
missingok
notifempty
create 777 root root
dateext
dateformat -%Y-%m-%d.log
}

/dist/logs/ngxway.error.log {
su root root
daily
compress
rotate 7
missingok
notifempty
create 777 root root
dateext
dateformat -%Y-%m-%d.log
}
Empty file added scripts/logs/logrotate.sh
Empty file.

0 comments on commit a01b372

Please sign in to comment.