Mainly add external monitoring of mail server
[distro-setup] / filesystem / usr / local / bin / mycheckrestart
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
5
6 if [[ $EUID != 0 ]]; then s=sudo; fi
7
8 set -eE -o pipefail
9 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
10
11 hn=$(hostname -f)
12 source /a/bin/bash_unpublished/source-state
13 if [[ $HOSTNAME != "$MAIL_HOST" && $hn != li.b8.nz && ! $DISPLAY ]]; then
14 exit 0
15 fi
16
17 cmd="$s /usr/sbin/checkrestart -p"
18 if [[ $($cmd | sed '/^Found 0 processes using old versions of upgraded files$/d' | wc -l) != 0 ]]; then
19 $cmd
20 fi