From 070f07635ab093b7ac18d3db7df2cb13ab7930bf Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Tue, 19 Jul 2022 15:56:12 -0700 Subject: [PATCH] change webalizer cron to systemd timer --- install.sh | 7 +++++-- sbin/split-apache-logfile.pl | 5 +++++ .../webalizer => sbin/webalizer-cron.sh | 0 systemd/webalizer.service | 11 +++++++++++ systemd/webalizer.timer | 16 ++++++++++++++++ update.sh | 14 ++++++++++++++ 6 files changed, 51 insertions(+), 2 deletions(-) rename etc/cron.daily/webalizer => sbin/webalizer-cron.sh (100%) create mode 100644 systemd/webalizer.service create mode 100644 systemd/webalizer.timer diff --git a/install.sh b/install.sh index 3e54497..b135ef9 100755 --- a/install.sh +++ b/install.sh @@ -131,9 +131,12 @@ fi apt -y install webalizer cp etc/logrotate.d/apache2 /etc/logrotate.d/apache2 chmod 644 /etc/logrotate.d/apache2 -cp etc/cron.daily/webalizer /etc/cron.daily/webalizer -chmod 755 /etc/cron.daily/webalizer +rm /etc/cron.daily/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 cp html/status.php /srv/www/html diff --git a/sbin/split-apache-logfile.pl b/sbin/split-apache-logfile.pl index 4568a8d..225ead9 100755 --- a/sbin/split-apache-logfile.pl +++ b/sbin/split-apache-logfile.pl @@ -52,6 +52,11 @@ foreach $virtualhost (@dir) { # set spool dir for temporary apache files $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 system("/usr/bin/find $spool_dir -type f -name '*.log' -exec rm {} +"); diff --git a/etc/cron.daily/webalizer b/sbin/webalizer-cron.sh similarity index 100% rename from etc/cron.daily/webalizer rename to sbin/webalizer-cron.sh diff --git a/systemd/webalizer.service b/systemd/webalizer.service new file mode 100644 index 0000000..67b7129 --- /dev/null +++ b/systemd/webalizer.service @@ -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 diff --git a/systemd/webalizer.timer b/systemd/webalizer.timer new file mode 100644 index 0000000..83eea9e --- /dev/null +++ b/systemd/webalizer.timer @@ -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 diff --git a/update.sh b/update.sh index 50d8549..c967627 100755 --- a/update.sh +++ b/update.sh @@ -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 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