Skip to content

Instantly share code, notes, and snippets.

@pancudaniel7
Last active January 18, 2024 20:52
Show Gist options
  • Save pancudaniel7/eaafcabc20374dd3f353273bda7e81ff to your computer and use it in GitHub Desktop.
Save pancudaniel7/eaafcabc20374dd3f353273bda7e81ff to your computer and use it in GitHub Desktop.
#!/usr/bin/bash
# Logrotate Configuration
echo "Setting up Logrotate configuration for your application..."
sudo cat <<EOF > /etc/log_size_check.conf
/var/log/syslog {
su root root
size 100M
copytruncate
rotate 30
compress
missingok
notifempty
delaycompress
postrotate
/usr/lib/rsyslog/rsyslog-rotate
endscript
}
EOF
echo "Creating Systemd service file for Logrotate..."
sudo cat <<EOF > /etc/systemd/system/log_size_check.service
[Unit]
Description=Rotate log files if size exceeded
[Service]
ExecStart=/usr/sbin/logrotate /etc/log_size_check.conf
EOF
# Systemd Timer File
echo "Creating Systemd timer file for Logrotate..."
sudo cat <<EOF > /etc/systemd/system/log_size_check.timer
[Unit]
Description=Run logrotate every 10 minutes
[Timer]
OnCalendar=*:0/10
Persistent=true
[Install]
WantedBy=timers.target
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment