retire da-backup checks
[mirror/dsa-nagios.git] / dsa-nagios-checks / sbin / dsa-update-apt-status
index 2c6347f..c506fea 100755 (executable)
@@ -1,7 +1,29 @@
-#!/bin/sh
+#!/bin/bash
+
+# Copyright 2009 Peter Palfrader
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 UPDATE_RUNS=3
-STATUS=/var/cache/dsa/nagios/apt
+STATUSDIR=/var/cache/dsa/nagios
+STATUS="${STATUSDIR}"/apt
 SLEEP_MAX=$(( 15 * 60 ))
 MAX_AGE=$(( 23 * 60 * 60 ))
 
@@ -29,9 +51,11 @@ run_required() {
        return $norun
 }
 
+mkdir -p "${STATUSDIR}"
+
 # do stuff only when required, or when asked to
 if [ "${1:-""}" != "-f" ] ; then
-       run_required || exit
+       run_required || exit 0
 fi
 
 # sleep if called non-interactively
@@ -42,7 +66,7 @@ fi
 # run apt-get update, retry a few times if it fails
 count=0
 while [ "$count" -lt "$UPDATE_RUNS" ]; do
-       apt-get update -qq >/dev/null >&2
+       flock -e /var/lib/apt/lists apt-get update -qq >/dev/null >&2
        if [ "$?" = "0" ]; then break; fi
        sleep $(( $RANDOM % 600 ))
        count="$(( $count + 1 ))"