244e0a51f09f1fac594e255848d1f3c24d9f5a7e
[log-quiet] / sysd-prom-fail-install
1 #!/bin/bash
2 # Copyright (C) 2022 Ian Kelling
3
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
7
8 # http://www.apache.org/licenses/LICENSE-2.0
9
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.
15
16 source /a/bin/errhandle/err
17 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
18
19 ser_name=$1
20
21 mkdir -p /var/lib/prometheus/node-exporter
22
23 f=/var/local/sysd-prom-fail/${ser_name}-result-fail.prom
24
25
26 if [[ ! -s /var/lib/prometheus/node-exporter/${ser_name}-result-fail.premerge ]]; then
27 SERVICE_RESULT=success /usr/local/bin/sysd-prom-fail $ser_name
28 fi
29
30 tmp=$(mktemp)
31
32 cat >>$tmp <<EOF
33 [Service]
34 ExecStopPost=+/usr/local/bin/sysd-prom-fail $ser_name
35 EOF
36
37 dir=/etc/systemd/system/$ser_name.service.d
38 mkdir -p $dir
39 out=$(rsync -cipgo --chmod=644 --chown=root:root $tmp $dir/sysd-prom-fail.conf)
40 if [[ $out ]]; then
41 echo $0: systemctl daemon-reload
42 systemctl daemon-reload
43 if systemctl is-active $ser_name &>/dev/null; then
44 echo $0: systemctl restart $ser_name
45 systemctl restart $ser_name ||:
46 fi
47 fi