40 lines
1.0 KiB
Bash
40 lines
1.0 KiB
Bash
#!/bin/bash
|
|
# Make sure script is ran as root
|
|
if [[ $EUID -ne 0 ]]; then
|
|
exec sudo /bin/bash "$0" "$@"
|
|
fi
|
|
|
|
logrotate --version 2>&1 || (
|
|
echo "Installing Logrotate..."
|
|
apt install logrotate -y 2>>install.log &&
|
|
logrotate --version
|
|
)
|
|
if ! grep -q "/var/www/\*/logs/\*\.log" "/etc/logrotate.d/apache2"; then
|
|
echo "Adding logrotate config"
|
|
cat <<EOT >> "/etc/logrotate.d/apache2"
|
|
/var/www/*/logs/*.log {
|
|
su root root
|
|
maxsize 50M
|
|
daily
|
|
missingok
|
|
rotate 7
|
|
compress
|
|
delaycompress
|
|
notifempty
|
|
create 640 root adm
|
|
sharedscripts
|
|
postrotate
|
|
if invoke-rc.d apache2 status > /dev/null 2>&1; then \
|
|
invoke-rc.d apache2 reload > /dev/null 2>&1; \
|
|
fi;
|
|
endscript
|
|
prerotate
|
|
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
|
|
run-parts /etc/logrotate.d/httpd-prerotate; \
|
|
fi; \
|
|
endscript
|
|
}
|
|
EOT
|
|
fi
|
|
|
|
echo 'Installation complete' |