From cc420ece827ac83e29ce09084c3fa276ed7b0bae Mon Sep 17 00:00:00 2001 From: chunangli Date: Mon, 6 Feb 2023 10:42:41 +0800 Subject: [PATCH 1/4] If sonic-cfggen exec failed, do not update rsyslog.conf. Signed-off-by: Chun'ang Li --- files/build_templates/docker_image_ctl.j2 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 2c7d8a7d6d04..cc8b7135f741 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -44,12 +44,19 @@ function updateSyslogConf() fi CONTAINER_NAME="$DOCKERNAME" TMP_FILE="/tmp/rsyslog.$CONTAINER_NAME.conf" + failed="false" {%- if docker_container_name == "database" %} python -c "import jinja2, os; paths=['/usr/share/sonic/templates']; loader = jinja2.FileSystemLoader(paths); env = jinja2.Environment(loader=loader, trim_blocks=True); template_file='/usr/share/sonic/templates/rsyslog-container.conf.j2'; template = env.get_template(os.path.basename(template_file)); data=template.render({\"target_ip\":\"$TARGET_IP\",\"container_name\":\"$CONTAINER_NAME\"}); print(data)" > $TMP_FILE {%- else %} sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog-container.conf.j2 -a "{\"target_ip\": \"$TARGET_IP\", \"container_name\": \"$CONTAINER_NAME\" }" > $TMP_FILE + if [ $? -ne 0 ]; then + echo "Error: Execute sonic-cfggen failed." + failed="true" + fi {%- endif %} - docker cp $TMP_FILE ${DOCKERNAME}:/etc/rsyslog.conf + if [ "$failed" == "false" ]; then + docker cp $TMP_FILE ${DOCKERNAME}:/etc/rsyslog.conf + fi rm -rf $TMP_FILE } function ebtables_config() From e96e18aa4781af3f8d011cf9dcf1f3c34e9e89c6 Mon Sep 17 00:00:00 2001 From: chunangli Date: Mon, 6 Feb 2023 15:31:14 +0800 Subject: [PATCH 2/4] If sonic-cfggen exec failed use '-d', remote '-d' and use default value to generate conf. Signed-off-by: Chun'ang Li --- files/image_config/rsyslog/rsyslog-container.conf.j2 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/files/image_config/rsyslog/rsyslog-container.conf.j2 b/files/image_config/rsyslog/rsyslog-container.conf.j2 index 4e2c90b548b2..a6419eba846a 100644 --- a/files/image_config/rsyslog/rsyslog-container.conf.j2 +++ b/files/image_config/rsyslog/rsyslog-container.conf.j2 @@ -28,9 +28,13 @@ $ModLoad imuxsock # provides support for local system logging {% if rate_limit_interval is defined %} $SystemLogRateLimitInterval {{ rate_limit_interval }} +{% else %} +$SystemLogRateLimitInterval 300 {% endif %} {% if rate_limit_burst is defined %} $SystemLogRateLimitBurst {{ rate_limit_burst }} +{% else %} +$SystemLogRateLimitBurst 20000 {% endif %} #$ModLoad imklog # provides kernel logging support From a8ebc77b71662b35bec8ac3ce45adc08313e0f53 Mon Sep 17 00:00:00 2001 From: chunangli Date: Mon, 6 Feb 2023 15:33:57 +0800 Subject: [PATCH 3/4] If sonic-cfggen exec failed use '-d', remote '-d' and use default value to generate conf. Signed-off-by: Chun'ang Li --- files/build_templates/docker_image_ctl.j2 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index cc8b7135f741..69cf58bc083b 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -50,13 +50,11 @@ function updateSyslogConf() {%- else %} sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog-container.conf.j2 -a "{\"target_ip\": \"$TARGET_IP\", \"container_name\": \"$CONTAINER_NAME\" }" > $TMP_FILE if [ $? -ne 0 ]; then - echo "Error: Execute sonic-cfggen failed." - failed="true" + echo "Error: Execute sonic-cfggen -d failed. Execute without '-d'." + sonic-cfggen -t /usr/share/sonic/templates/rsyslog-container.conf.j2 -a "{\"target_ip\": \"$TARGET_IP\", \"container_name\": \"$CONTAINER_NAME\" }" > $TMP_FILE fi {%- endif %} - if [ "$failed" == "false" ]; then - docker cp $TMP_FILE ${DOCKERNAME}:/etc/rsyslog.conf - fi + docker cp $TMP_FILE ${DOCKERNAME}:/etc/rsyslog.conf rm -rf $TMP_FILE } function ebtables_config() From ee80ea80ebe64995419336a2cdb0d18bd069393b Mon Sep 17 00:00:00 2001 From: chunangli Date: Mon, 6 Feb 2023 15:37:33 +0800 Subject: [PATCH 4/4] update --- files/build_templates/docker_image_ctl.j2 | 1 - 1 file changed, 1 deletion(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 69cf58bc083b..ec94fd420303 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -44,7 +44,6 @@ function updateSyslogConf() fi CONTAINER_NAME="$DOCKERNAME" TMP_FILE="/tmp/rsyslog.$CONTAINER_NAME.conf" - failed="false" {%- if docker_container_name == "database" %} python -c "import jinja2, os; paths=['/usr/share/sonic/templates']; loader = jinja2.FileSystemLoader(paths); env = jinja2.Environment(loader=loader, trim_blocks=True); template_file='/usr/share/sonic/templates/rsyslog-container.conf.j2'; template = env.get_template(os.path.basename(template_file)); data=template.render({\"target_ip\":\"$TARGET_IP\",\"container_name\":\"$CONTAINER_NAME\"}); print(data)" > $TMP_FILE {%- else %}