From dd35c9c2beec828fa2eb4c7777b33247b37ebddd Mon Sep 17 00:00:00 2001 From: Marissa Zhang Date: Wed, 17 Jul 2024 11:04:50 -0500 Subject: [PATCH 1/2] add logrotate & its cron job for log files in /var/log/httpd dir(testing parameters) --- Dockerfile.testing | 6 +++++- logrotate-http.conf | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 logrotate-http.conf diff --git a/Dockerfile.testing b/Dockerfile.testing index eb015e5..b32967c 100644 --- a/Dockerfile.testing +++ b/Dockerfile.testing @@ -9,7 +9,7 @@ RUN \ yum update -y && \ (yum install -y git-core || yum install -y git) && \ yum install -y --enablerepo=osg-upcoming condor && \ - yum install -y python3-pip httpd mod_auth_openidc mod_ssl python3-mod_wsgi && \ + yum install -y python3-pip httpd mod_auth_openidc mod_ssl python3-mod_wsgi logrotate && \ yum install -y make && \ yum clean all && rm -rf /var/cache/yum/* @@ -28,8 +28,12 @@ RUN pip3 install -U pip && pip3 install -r /opt/registry/requirements.txt # Use our weird grid-security cert/key location RUN rm /etc/httpd/conf.d/ssl.conf +# Setup cron job for logrotate to run every 5 minutes +RUN crontab -l | { cat; echo "* * * * * /usr/sbin/logrotate /etc/logrotate.d/httpd >> /var/log/cron 2>&1"; } | crontab - + COPY register.py /usr/bin COPY supervisor-apache.conf /etc/supervisord.d/40-apache.conf +COPY logrotate-http.conf /etc/logrotate.d/httpd COPY examples/apache.conf /etc/httpd/conf.d/ ENV CONFIG_DIR=/srv diff --git a/logrotate-http.conf b/logrotate-http.conf new file mode 100644 index 0000000..83de620 --- /dev/null +++ b/logrotate-http.conf @@ -0,0 +1,14 @@ +/var/log/httpd/*.log { + maxsize 10K + dateext + dateformat -%Y%m%d-%s + rotate 2 + missingok + notifempty + compress + delaycompress + sharedscripts + postrotate + PID=$(pgrep -o httpd) && kill -USR1 $PID + endscript +} From 5f0d4b7026c2e7ae6514dcf65163c303a8dcd2b7 Mon Sep 17 00:00:00 2001 From: Marissa Zhang Date: Thu, 18 Jul 2024 16:21:05 -0500 Subject: [PATCH 2/2] Improve logrotate parameters based on Mat's feedback --- Dockerfile.testing | 4 ++-- logrotate-http.conf | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Dockerfile.testing b/Dockerfile.testing index b32967c..bf20ec9 100644 --- a/Dockerfile.testing +++ b/Dockerfile.testing @@ -28,8 +28,8 @@ RUN pip3 install -U pip && pip3 install -r /opt/registry/requirements.txt # Use our weird grid-security cert/key location RUN rm /etc/httpd/conf.d/ssl.conf -# Setup cron job for logrotate to run every 5 minutes -RUN crontab -l | { cat; echo "* * * * * /usr/sbin/logrotate /etc/logrotate.d/httpd >> /var/log/cron 2>&1"; } | crontab - +# Setup cron job for logrotate to run as root every day +RUN echo "0 0 * * * root /usr/sbin/logrotate /etc/logrotate.d/httpd >> /var/log/cron 2>&1" > /etc/cron.d/logrotate-httpd COPY register.py /usr/bin COPY supervisor-apache.conf /etc/supervisord.d/40-apache.conf diff --git a/logrotate-http.conf b/logrotate-http.conf index 83de620..c90679b 100644 --- a/logrotate-http.conf +++ b/logrotate-http.conf @@ -1,14 +1,12 @@ /var/log/httpd/*.log { - maxsize 10K - dateext - dateformat -%Y%m%d-%s - rotate 2 + maxsize 100M + rotate 20 missingok notifempty compress delaycompress sharedscripts postrotate - PID=$(pgrep -o httpd) && kill -USR1 $PID + PID=$(pgrep -o httpd); if [ "$PID" ]; then kill -USR1 $PID; fi endscript }