change webalizer cron to systemd timer

This commit is contained in:
Matthew Saunders Brown 2022-07-19 15:56:12 -07:00
parent e300369ab0
commit 070f07635a
6 changed files with 51 additions and 2 deletions

View File

@ -131,9 +131,12 @@ fi
apt -y install webalizer apt -y install webalizer
cp etc/logrotate.d/apache2 /etc/logrotate.d/apache2 cp etc/logrotate.d/apache2 /etc/logrotate.d/apache2
chmod 644 /etc/logrotate.d/apache2 chmod 644 /etc/logrotate.d/apache2
cp etc/cron.daily/webalizer /etc/cron.daily/webalizer rm /etc/cron.daily/webalizer
chmod 755 /etc/cron.daily/webalizer
rmdir /srv/www/webalizer rmdir /srv/www/webalizer
cp systemd/webalizer.* /usr/lib/systemd/system/
chmod 644 /usr/lib/systemd/system/webalizer.*
systemctl enable webalizer.timer
systemctl start webalizer.timer
# install status.php # install status.php
cp html/status.php /srv/www/html cp html/status.php /srv/www/html

View File

@ -52,6 +52,11 @@ foreach $virtualhost (@dir) {
# set spool dir for temporary apache files # set spool dir for temporary apache files
$spool_dir="/var/spool/apache2"; $spool_dir="/var/spool/apache2";
# creatre spool dir if it doesn't already exist
if (!-d "$spool_dir") {
system("mkdir $spool_dir");
}
# remove any previous files from spool dir # remove any previous files from spool dir
system("/usr/bin/find $spool_dir -type f -name '*.log' -exec rm {} +"); system("/usr/bin/find $spool_dir -type f -name '*.log' -exec rm {} +");

11
systemd/webalizer.service Normal file
View File

@ -0,0 +1,11 @@
# vmail-stack
# https://git.stack-source.com/msb/vmail-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
#
[Unit]
Description=Webalizer - generate stats from apache logs
After=logrotate.service
[Service]
Type=simple
ExecStart=/usr/local/sbin/webalizer-cron.sh

16
systemd/webalizer.timer Normal file
View File

@ -0,0 +1,16 @@
# vmail-stack
# https://git.stack-source.com/msb/vmail-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
#
[Unit]
Description=Webalizer - analyze apache logs once per day
After=logrotate.timer
[Timer]
OnCalendar=daily
AccuracySec=12h
Persistent=true
Unit=webalizer.service
[Install]
WantedBy=timers.target

View File

@ -75,3 +75,17 @@ if ! diff -q libexec/command-not-found-handle /usr/local/libexec/command-not-fou
echo "/usr/local/libexec/command-not-found-handle updated" echo "/usr/local/libexec/command-not-found-handle updated"
echo echo
fi fi
# check systemd timer for update
if ! diff -q systemd/webalizer.service /usr/lib/systemd/system/webalizer.service ; then
cp systemd/webalizer.service /usr/lib/systemd/system/webalizer.service
chmod 644 /usr/lib/systemd/system/webalizer.service
echo "systemd/webalizer.service updated"
echo
fi
if ! diff -q systemd/webalizer.timer /usr/lib/systemd/system/webalizer.timer ; then
cp systemd/webalizer.timer /usr/lib/systemd/system/webalizer.timer
chmod 644 /usr/lib/systemd/system/webalizer.timer
echo "systemd/webalizer.timer updated"
echo
fi