From d11bd3c7d4fd59a3262ec097e4e3523cdd1768ce Mon Sep 17 00:00:00 2001 From: "Villa, Joseph" Date: Mon, 14 Nov 2022 14:53:08 -0700 Subject: [PATCH 1/4] First commit for fixing issue with traffic_router log rotation Added new file for log4j2.xml as well as logrotate configuration. We may need to tweak further, maybe add an hourly logrotate file if we feel like. But this is a good start. I need to know the other places that I need to modify Traffic Router to make sure the changes get into the RPM. --- .../files/traffic_router.logrotate | 17 +++++++++ .../traffic-router/tasks/traffic_router.yml | 9 +++++ traffic_router/core/src/main/conf/log4j2.xml | 37 +++++++------------ .../src/main/lib/logrotate/traffic_router | 17 +++++++++ 4 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 infrastructure/ansible/roles/traffic-router/files/traffic_router.logrotate create mode 100644 traffic_router/core/src/main/lib/logrotate/traffic_router diff --git a/infrastructure/ansible/roles/traffic-router/files/traffic_router.logrotate b/infrastructure/ansible/roles/traffic-router/files/traffic_router.logrotate new file mode 100644 index 0000000000..cf6f862bd8 --- /dev/null +++ b/infrastructure/ansible/roles/traffic-router/files/traffic_router.logrotate @@ -0,0 +1,17 @@ +/opt/traffic_router/var/log/access.log { + daily + size 100m + compress + rotate 7 + dateformat -%d%m%Y + copytruncate +} + +/opt/traffic_router/var/log/traffic_router.log { + daily + size 100m + compress + rotate 7 + dateformat -%d%m%Y + copytruncate +} \ No newline at end of file diff --git a/infrastructure/ansible/roles/traffic-router/tasks/traffic_router.yml b/infrastructure/ansible/roles/traffic-router/tasks/traffic_router.yml index b23314454b..e8f6490226 100644 --- a/infrastructure/ansible/roles/traffic-router/tasks/traffic_router.yml +++ b/infrastructure/ansible/roles/traffic-router/tasks/traffic_router.yml @@ -94,6 +94,15 @@ become: yes register: tr_systemd +- name: Copy traffic router logrotate file + file: + src: traffic_router.logrotate + dest: /etc/logrotate.d/traffic_router + mode: 0644 + owner: root + group: root + become: yes + - name: Reload systemd unit files if needed systemd: daemon_reload: yes diff --git a/traffic_router/core/src/main/conf/log4j2.xml b/traffic_router/core/src/main/conf/log4j2.xml index 5984d9d0e4..760eefdff7 100644 --- a/traffic_router/core/src/main/conf/log4j2.xml +++ b/traffic_router/core/src/main/conf/log4j2.xml @@ -13,41 +13,30 @@ See the License for the specific language governing permissions and limitations under the License. --> - + + - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - diff --git a/traffic_router/core/src/main/lib/logrotate/traffic_router b/traffic_router/core/src/main/lib/logrotate/traffic_router new file mode 100644 index 0000000000..2604d09a8b --- /dev/null +++ b/traffic_router/core/src/main/lib/logrotate/traffic_router @@ -0,0 +1,17 @@ +/opt/traffic_router/var/log/access.log { + daily + size 1k + compress + rotate 7 + dateformat -%d%m%Y + copytruncate +} + +/opt/traffic_router/var/log/traffic_router.log { + daily + size 1k + compress + rotate 7 + dateformat -%d%m%Y + copytruncate +} \ No newline at end of file From 55c9d3d74362b97619820c2ea2e97dfad95268df Mon Sep 17 00:00:00 2001 From: "Villa, Joseph" Date: Fri, 18 Nov 2022 22:34:37 -0700 Subject: [PATCH 2/4] Changes to build.sh and pom.xml files for building of TR Addition of logrotate. Still need to test. --- traffic_router/build/build_rpm.sh | 2 ++ traffic_router/build/pom.xml | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/traffic_router/build/build_rpm.sh b/traffic_router/build/build_rpm.sh index 56079e5847..f624f44906 100755 --- a/traffic_router/build/build_rpm.sh +++ b/traffic_router/build/build_rpm.sh @@ -39,6 +39,8 @@ buildRpmTrafficRouter () { export STARTUP_SCRIPT_DIR="/lib/systemd/system" export STARTUP_SCRIPT_LOC="../core/src/main/lib/systemd/system" + export LOGROTATE_SCRIPT_DIR="/etc/logrotate.d" + export LOGROTATE_SCRIPT_LOC="../core/src/main/lib/logrotate" cd "$TR_DIR" || { echo "Could not cd to $TR_DIR: $?"; return 1; } mvn -P rpm-build -Dmaven.test.skip=true -DminimumTPS=1 clean package || \ diff --git a/traffic_router/build/pom.xml b/traffic_router/build/pom.xml index 42ecedb639..5ee9f7dc38 100644 --- a/traffic_router/build/pom.xml +++ b/traffic_router/build/pom.xml @@ -208,6 +208,18 @@ + + ${env.LOGROTATE_SCRIPT_DIR} + false + 644 + root + root + + + ${env.LOGROTATE_SCRIPT_LOC} + + + ${deploy.dir}/webapps false From 3e63e510a794bc03fd3de1da84b070c0b821ad9f Mon Sep 17 00:00:00 2001 From: "Villa, Joseph" Date: Tue, 6 Dec 2022 12:16:57 -0700 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fffe51c255..96dcf32a2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - [#7137](https://github.com/apache/trafficcontrol/pull/7137) *Traffic Control Cache Config (t3c)* parent.config simulate topology for non topo delivery services. - [#7153](https://github.com/apache/trafficcontrol/pull/7153) *Traffic Control Cache Config (t3c)* Adds an extra T3C check for validity of an ssl cert (crash fix). - [#3965](https://github.com/apache/trafficcontrol/pull/3965) *Traffic Router* Traffic Router now always includes a `Content-Length` header in the response. +- [#6533](https://github.com/apache/trafficcontrol/issues/6533) *TR should not rename/recreate log files on rollover ## [7.0.0] - 2022-07-19 ### Added From afe4bb2f612ca04d958c6e2a9ab857b54965e5de Mon Sep 17 00:00:00 2001 From: "Villa, Joseph" Date: Tue, 6 Dec 2022 12:39:06 -0700 Subject: [PATCH 4/4] Update traffic_router.rst --- docs/source/admin/traffic_router.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/admin/traffic_router.rst b/docs/source/admin/traffic_router.rst index b640741d23..3d6aeb16f3 100644 --- a/docs/source/admin/traffic_router.rst +++ b/docs/source/admin/traffic_router.rst @@ -166,6 +166,8 @@ For the most part, the configuration files and :term:`Parameters` used by Traffi +----------------------------+-------------------------------------------+----------------------------------------------------------------------------------+----------------------------------------------------+ | log4j2.xml | various parameters | Configuration of ``log4j`` is documented on | N/A | | | | `their site `_; adjust as needed | | + | | | Log rotation is handled by logrotate. Relevant files are in /etc/logrotate.d and | | + | | | in /etc/cron.daily. | | +----------------------------+-------------------------------------------+----------------------------------------------------------------------------------+----------------------------------------------------+ | server.xml | various parameters | Traffic Router specific configuration for Apache Tomcat. See the Apache Tomcat | N/A | | | | `documentation `_ | |