From 8ee6ac80de0ce6c3dbb27631db68b9848a36f3fc Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 18 Apr 2020 04:36:37 +0530 Subject: [PATCH] systemd: run goaccess run every 10 minutes in non-live mode Signed-off-by: Harsh Shandilya --- systemd_units/goaccess-update.timer | 12 ++++++++++++ systemd_units/goaccess.service | 2 +- systemd_units/update.sh | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 systemd_units/goaccess-update.timer diff --git a/systemd_units/goaccess-update.timer b/systemd_units/goaccess-update.timer new file mode 100644 index 0000000..1c3b2f6 --- /dev/null +++ b/systemd_units/goaccess-update.timer @@ -0,0 +1,12 @@ +[Unit] +Description=Run goaccess every 10 minutes to update statistics +Requires=goaccess.service + +[Timer] +Unit=goaccess.service +OnUnitInactiveSec=10m +RandomizedDelaySec=10m +AccuracySec=1s + +[Install] +WantedBy=timers.target diff --git a/systemd_units/goaccess.service b/systemd_units/goaccess.service index c135f92..c66855f 100644 --- a/systemd_units/goaccess.service +++ b/systemd_units/goaccess.service @@ -10,7 +10,7 @@ RestartSec=2s Type=simple User=caddy Group=caddy -ExecStart=/usr/bin/goaccess --log-format=VCOMMON --ws-url=wss://stats.msfjarvis.dev/ws --output=/var/www/stats.msfjarvis.dev/index.html --log-file=/etc/logs/requests.log --no-query-string --anonymize-ip --double-decode --real-os --compression=zlib --real-time-html +ExecStart=/usr/bin/goaccess --log-format=VCOMMON --output=/var/www/stats.msfjarvis.dev/index.html --log-file=/etc/logs/requests.log --no-query-string --anonymize-ip --double-decode --real-os --compression=zlib Restart=always # Security diff --git a/systemd_units/update.sh b/systemd_units/update.sh index 440128f..8e25bcb 100755 --- a/systemd_units/update.sh +++ b/systemd_units/update.sh @@ -9,6 +9,7 @@ function prettyPrint() { # Grab all service names declare -a services=('caddy' 'goaccess' 'mirror-bot' 'mirror-bot-2' 'uno-bot' 'walls-bot' 'walls-bot-rs') +declare -a timers=('goaccess-update') # Now loop through each service and install it for service in "${services[@]}"; do @@ -29,3 +30,18 @@ for service in "${services[@]}"; do fi fi done + +for timer in "${timers[@]}"; do + if [ "${1}" ] && [[ ${timer} != "${1}" && "${timer}.timer" != "${1}" ]]; then + continue + fi + prettyPrint "Checking root access" + sudo -v || return 1 + prettyPrint "Installing ${timer}" + sudo cp -v "${timer}.timer" /etc/systemd/system/ + sudo systemctl daemon-reload + if [ -z "${NO_RESTART}" ]; then + prettyPrint "Enabling ${timer}" + sudo systemctl enable "${timer}.timer" + fi +done