2 # Copyright (C) 2022 Ian Kelling
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # usage: since this is a counter, in prometheus alert manager you will
17 # need to test something like: rate(node_systemd_unit_result_fail_count[30m]) > 0
19 source /a
/bin
/errhandle
/err
20 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
24 mkdir
-p /var
/lib
/prometheus
/node-exporter
26 f
=/var
/local
/sysd-prom-fail
/${ser_name}-result.prom
29 if [[ ! -s $f ]]; then
30 SERVICE_RESULT
=success
/usr
/local
/bin
/sysd-prom-fail
$ser_name
37 ExecStopPost=+/usr/local/bin/sysd-prom-fail $ser_name
40 dir
=/etc
/systemd
/system
/$ser_name.service.d
42 out
=$
(rsync
-cipgo --chmod=644 --chown=root
:root
$tmp $dir/sysd-prom-fail.conf
)
44 echo $0: systemctl daemon-reload
45 systemctl daemon-reload
46 if systemctl is-active
$ser_name &>/dev
/null
; then
47 echo $0: systemctl restart
$ser_name
48 systemctl restart
$ser_name ||
:
52 # todo: make uninstall script