Debian Codegraph @

dsa/sbin/dsa-update-apt-status

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 # Copyright 2009 Peter Palfrader
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 UPDATE_RUNS=3
•25 STATUSDIR=/var/cache/dsa/nagiosscip-shell filesystem . . `/var/cache/dsa/nagios`.
26 STATUS="${STATUSDIR}"/apt
27 SLEEP_MAX=$(( 15 * 60 ))
28 MAX_AGE=$(( 23 * 60 * 60 ))
29
30 # we want to run if any of the following things is true
31 # - we have never run before
32 # - var/lib/dpkg/status has been touched since the last run
33 # - var/cache/apt/pkgcache.bin has been touched since the last run
34 # - our last run ended with 'apt-get update failed'
35 # - our last run has been more than MAX_AGE (23hrs) ago
36 run_requiredscip-shell shell shell-project 0.0.0 run_required().() {
37 local run=0
38 local norun=1
39
40 [scip-shell system . . `[`. -e "$STATUS" ] || return $run
41 [scip-shell system . . `[`. /var/lib/dpkg/statusscip-shell filesystem . . `/var/lib/dpkg/status`. -nt "$STATUS" ] && return $run
42 [scip-shell system . . `[`. /var/cache/apt/pkgcache.binscip-shell filesystem . . `/var/cache/apt/pkgcache.bin`. -nt "$STATUS" ] && return $run
43 grepscip-shell system . . grep. "apt-get update failed" "$STATUS" > /dev/nullscip-shell filesystem . . `/dev/null`. && return $run
44
45 local last_mod
46 last_mod=`statscip-shell system . . stat. -c "%Y" "$STATUS"`
47 now=`datescip-shell system . . date. +%s`
48 age=$(( $now - $last_mod ))
49 [scip-shell system . . `[`. "$age" -gt "$MAX_AGE" ] && return $run
50
51 return $norun
52 }
53
54 mkdirscip-shell system . . mkdir. -p "${STATUSDIR}"
55
56 # do stuff only when required, or when asked to
57 if [scip-shell system . . `[`. "${1:-""}" != "-f" ] ; then
58 run_requiredscip-shell shell shell-project 0.0.0 run_required(). || exit 0
59 fi
60
61 # sleep if called non-interactively
62 if [scip-shell system . . `[`. -z "$TERM" -o "$TERM" = "dumb" ]; then
63 sleepscip-shell system . . sleep. $(( $RANDOM % $SLEEP_MAX ))
64 fi
65
66 # run apt-get update, retry a few times if it fails
67 count=0
68 while [scip-shell system . . `[`. "$count" -lt "$UPDATE_RUNS" ]; do
69 flockscip-shell system . . flock. -e /var/lib/apt/listsscip-shell filesystem . . `/var/lib/apt/lists`. apt-get update -qq >/dev/nullscip-shell filesystem . . `/dev/null`. >&2
70 if [scip-shell system . . `[`. "$?" = "0" ]; then break; fi
71 sleepscip-shell system . . sleep. $(( $RANDOM % 600 ))
72 count="$(( $count + 1 ))"
73 done
74 if [scip-shell system . . `[`. "$count" -ge "$UPDATE_RUNS" ]; then
75 (echoscip-shell system . . echo. "WARNING"
76 echoscip-shell system . . echo. "apt-get update failed") > "$STATUS"
77 exit 1
78 fi
79
80 # run the apt check itself
81 tmp=`mktempscip-shell system . . mktemp.`
82 trap "rm -f '$tmp'" exit
83 #/usr/share/dsa/apt-status-check --noupdate --timeout=600 > "$tmp"
•84 /usr/lib/nagios/plugins/dsa-check-packagesscip-shell filesystem . . `/usr/lib/nagios/plugins/dsa-check-packages`. > "$tmp"
85 result="$?"
86 case "$result" in
87 0)
88 st="OK"
89 ;;
90 1)
91 st="WARNING"
92 ;;
93 2)
94 st="CRITICAL"
95 ;;
96 *)
97 st="UNKNOWN"
98 ;;
99 esac
100 (echoscip-shell system . . echo. "$st"; catscip-shell system . . cat. "$tmp") > "$STATUS"