Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Created February 6, 2018 16:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tuxfight3r/52162ed1abc1b043cb2fe35c821570f6 to your computer and use it in GitHub Desktop.
Save tuxfight3r/52162ed1abc1b043cb2fe35c821570f6 to your computer and use it in GitHub Desktop.
custom splunk journald logrotate
# Rotate client logs
# log file already has this context set.
# -rw-r-----. root root system_u:object_r:var_log_t:s0 /var/log/journald_splunk.log
# -rw-r-----. root root system_u:object_r:var_log_t:s0 /var/log/journald_splunk.log-2018020315
/var/log/journald_splunk.log {
hourly
maxsize 3M
rotate 3
missingok
delaycompress
notifempty
sharedscripts
create 640 root root
prerotate
/bin/systemctl stop journald-splunk-log.service
endscript
postrotate
/bin/systemctl start journald-splunk-log.service
endscript
}
[Unit]
Description=Journald to Splunk Log Converter
After=network.target
[Service]
Type=simple
Restart=always
ExecStartPre=/usr/bin/journalctl --vacuum-time=30days
ExecStart=/bin/sh -c '/usr/bin/journalctl --since "1 hour ago" -f -o json > /var/log/journald_splunk.log 2>&1'
RestartSec=600s
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment