Skip to content

Commit

Permalink
Merge pull request #30 from ehh-why-its-so-hard/logrotate
Browse files Browse the repository at this point in the history
feat: add logrotate
  • Loading branch information
daniel1302 authored Dec 8, 2024
2 parents 0e51fe0 + ae82e08 commit 15561de
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
26 changes: 26 additions & 0 deletions roles/vega_common/files/etc/logrotate.d/rsyslog
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/var/log/syslog
/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
{
size 5G
rotate 3
daily
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
/usr/lib/rsyslog/rsyslog-rotate
endscript
}
5 changes: 5 additions & 0 deletions roles/vega_common/files/usr/lib/rsyslog/rsyslog-rotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

if [ -d /run/systemd/system ]; then
systemctl kill -s HUP rsyslog.service
fi
8 changes: 8 additions & 0 deletions roles/vega_common/handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Restart logrotate
ansible.builtin.service:
state: restarted
daemon_reload: true
enabled: true
name: logrotate
listen: "Restart logrotate"
31 changes: 31 additions & 0 deletions roles/vega_common/tasks/logrotate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- name: Install logrotate
ansible.builtin.apt:
pkg:
- logrotate
retries: 3
delay: 3
register: logrotate_install
until: logrotate_install is succeeded

- name: Copy logrotate scripts
ansible.builtin.copy:
src: "{{- item -}}"
dest: "/{{- item -}}"
owner: root
group: root
mode: '0755'
notify: "Restart logrotate"
with_items:
- usr/lib/rsyslog/rsyslog-rotate

- name: Copy log rotate configs
ansible.builtin.copy:
src: "{{- item -}}"
dest: "/{{- item -}}"
owner: root
group: root
mode: '0644'
notify: "Restart logrotate"
with_items:
- etc/logrotate.d/rsyslog
3 changes: 3 additions & 0 deletions roles/vega_common/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
- name: Install dasel
ansible.builtin.import_tasks: dasel.yaml

- name: Install logrotate
ansible.builtin.import_tasks: logrotate.yaml

- name: Set a hostname
ansible.builtin.hostname:
name: "{{- vega_common_custom_hostname -}}"
Expand Down

0 comments on commit 15561de

Please sign in to comment.