icecast improvements
[distro-setup] / epanic-clean
index f69182b9482b7146501670b4c2f32df910c359bf..f6328c2b41a26bd27624098d013f872b307c68d6 100755 (executable)
@@ -1,6 +1,25 @@
 #!/bin/bash
 #!/bin/bash
-# Copyright (C) 2019 Ian Kelling
-# SPDX-License-Identifier: AGPL-3.0-or-later
+# I, Ian Kelling, follow the GNU license recommendations at
+# https://www.gnu.org/licenses/license-recommendations.en.html. They
+# recommend that small programs, < 300 lines, be licensed under the
+# Apache License 2.0. This file contains or is part of one or more small
+# programs. If a small program grows beyond 300 lines, I plan to switch
+# its license to GPL.
+
+# Copyright 2024 Ian Kelling
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+#     http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 
 # The panic log regularly gets some stuff in it we dont want to fix.
 # Detect it and wipe it out.
 
 # The panic log regularly gets some stuff in it we dont want to fix.
 # Detect it and wipe it out.
@@ -31,6 +50,11 @@ v() {
   fi
 }
 
   fi
 }
 
+spamd_ser=spamd
+if systemctl cat spamassassin &>/dev/null; then
+  spamd_ser=spamassassin
+fi
+
 
 pl=/var/log/exim4/paniclog
 main() {
 
 pl=/var/log/exim4/paniclog
 main() {
@@ -89,7 +113,7 @@ main() {
       jmax="$(date -d @$sec_max "+%F %H:%M:%S")"
       description=$(systemctl cat $service | sed -rn 's/^ *Description=(.*)/\1/p')
       jrregex="^Starting $description"
       jmax="$(date -d @$sec_max "+%F %H:%M:%S")"
       description=$(systemctl cat $service | sed -rn 's/^ *Description=(.*)/\1/p')
       jrregex="^Starting $description"
-      if [[ $service == spamassassin ]]; then
+      if [[ $service == "$spamd_ser" ]]; then
         jrregex+="\|^spamd: restarting"
       fi
       d "jrregex=$jrregex jmin=$jmin jmax=$jmax"
         jrregex+="\|^spamd: restarting"
       fi
       d "jrregex=$jrregex jmin=$jmin jmax=$jmax"
@@ -110,9 +134,9 @@ main() {
         sed -ri "/$regex/d" $pl
       fi
     fi
         sed -ri "/$regex/d" $pl
       fi
     fi
-  done <<'EOF'
+  done <<EOF
 clamav-daemon malware acl condition
 clamav-daemon malware acl condition
-spamassassin spam acl condition
+$spamd_ser spam acl condition
 EOF
   ### end removing panic lines due to service restarts ###
 
 EOF
   ### end removing panic lines due to service restarts ###
 
@@ -146,6 +170,12 @@ EOF
   # I think we could alert on anything else older than 61 seconds,
   # but lets just add some slack, make it 2 minutes.
   while read -r day time _; do
   # I think we could alert on anything else older than 61 seconds,
   # but lets just add some slack, make it 2 minutes.
   while read -r day time _; do
+    # some lines dont have dates, just skip them
+    # 2022-09-16 15:21:06.250 [438097] Exim configuration error:
+    #  can't redefine an undefined macro "REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOSTS"
+    if [[ $day != [2-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] ]]; then
+      continue
+    fi
     log_s=$(date -d "$day $time" +%s)
     if (( EPOCHSECONDS - 120 > log_s  )); then
       pr_metric=1
     log_s=$(date -d "$day $time" +%s)
     if (( EPOCHSECONDS - 120 > log_s  )); then
       pr_metric=1
@@ -172,7 +202,7 @@ if [[ ! -w $pl-archive ]]; then
   chmod 664 $pl-archive
 fi
 
   chmod 664 $pl-archive
 fi
 
-if [[ $INVOCATION_ID ]]; then
+if [[ $PPID == 1 ]]; then
   loop-main
 else
   main
   loop-main
 else
   main