Skip to content

Commit

Permalink
Modify SLE remediation for ensure_logrotate_activated
Browse files Browse the repository at this point in the history
In SLE platforms it is prefered to utilise logrotate timer service for log rotation functionality.
Check remains sam, and will accept cron-based configuration, but in case of missing scheduled timer,
timer service is prefered over cron.
  • Loading branch information
teacup-on-rockingchair committed Apr 23, 2023
1 parent 70a14df commit cd7b4ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
regexp: '^[\s]*(weekly|monthly|yearly)$'
state: absent

{{% if 'sle' in product %}}
- name: Enable timer logrotate
systemd:
name: "logrotate.timer"
enabled: "yes"
state: "started"
{{% else %}}
- name: Configure cron.daily if not already
block:
- name: Add shebang
Expand All @@ -31,3 +38,4 @@
path: "/etc/cron.daily/logrotate"
line: '/usr/sbin/logrotate /etc/logrotate.conf'
regexp: '^[\s]*/usr/sbin/logrotate[\s\S]*/etc/logrotate.conf$'
{{% endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ grep -q "^daily$" $LOGROTATE_CONF_FILE|| echo "daily" >> $LOGROTATE_CONF_FILE
# remove any line configuring weekly, monthly or yearly rotation
sed -i '/^\s*\(weekly\|monthly\|yearly\).*$/d' $LOGROTATE_CONF_FILE

{{% if 'sle' in product %}}
# enable logrotate timer service
SYSTEMCTL_EXEC='/usr/bin/systemctl'
"$SYSTEMCTL_EXEC" start 'logrotate.timer'
"$SYSTEMCTL_EXEC" enable 'logrotate.timer'
{{% else %}}
# configure cron.daily if not already
if ! grep -q "^[[:space:]]*/usr/sbin/logrotate[[:alnum:][:blank:][:punct:]]*$LOGROTATE_CONF_FILE$" $CRON_DAILY_LOGROTATE_FILE; then
echo "#!/bin/sh" > $CRON_DAILY_LOGROTATE_FILE
echo "/usr/sbin/logrotate $LOGROTATE_CONF_FILE" >> $CRON_DAILY_LOGROTATE_FILE
fi
{{% endif %}}

0 comments on commit cd7b4ab

Please sign in to comment.