summaryrefslogtreecommitdiff
path: root/debian
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2017-04-28 11:11:53 +0200
committerJulian Andres Klode <jak@debian.org>2017-05-05 14:45:21 +0200
commit820b469f0648eaa63356a812cd96ca8c4af6ac71 (patch)
treea7457ad779c9c164eae04949be2d992f7389994c /debian
parentf1f796a3c506400f54f4a39b6f43b0494cfb210c (diff)
apt.systemd.daily: Add locking
Use a lock file to make sure only one instance of the script is running at the same time. (cherry picked from commit ea49b66372912354143b810e2826301d651a2b37)
Diffstat (limited to 'debian')
-rwxr-xr-xdebian/apt.systemd.daily18
1 files changed, 14 insertions, 4 deletions
diff --git a/debian/apt.systemd.daily b/debian/apt.systemd.daily
index a8d98494b..22cbbded6 100755
--- a/debian/apt.systemd.daily
+++ b/debian/apt.systemd.daily
@@ -292,6 +292,16 @@ debug_echo()
# ------------------------ main ----------------------------
+# Maintain a lock on fd 3, so we can't run the script twice at the same
+# time.
+LOCKFD=3
+eval $(apt-config shell StateDir Dir::State/d)
+exec 3>${StateDir}/daily_lock
+if ! flock -w 3600 $LOCKFD; then
+ echo "E: Could not acquire lock" >&2
+ exit 1
+fi
+
if test -r /var/lib/apt/extended_states; then
# Backup the 7 last versions of APT's extended_states file
# shameless copy from dpkg cron
@@ -423,9 +433,9 @@ if [ "$1" = "update" -o -z "$1" ] ; then
DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp
if [ $UPDATED -eq 1 ] && check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then
if [ $Debdelta -eq 1 ]; then
- debdelta-upgrade >/dev/null 2>&1 || true
+ debdelta-upgrade >/dev/null 2>&1 $LOCKFD>&- || true
fi
- if eval apt-get $XAPTOPT -y -d dist-upgrade $XSTDERR; then
+ if eval apt-get $XAPTOPT -y -d dist-upgrade $XSTDERR $LOCKFD>&-; then
update_stamp $DOWNLOAD_UPGRADEABLE_STAMP
debug_echo "download upgradable (success)"
else
@@ -436,7 +446,7 @@ if [ "$1" = "update" -o -z "$1" ] ; then
fi
if which unattended-upgrade >/dev/null 2>&1 && check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $UnattendedUpgradeInterval; then
- if unattended-upgrade -d $XUUPOPT; then
+ if unattended-upgrade -d $XUUPOPT $LOCKFD>&-; then
update_stamp $DOWNLOAD_UPGRADEABLE_STAMP
debug_echo "unattended-upgrade -d (success)"
else
@@ -451,7 +461,7 @@ if [ "$1" = "install" -o -z "$1" ] ; then
# auto upgrade all upgradeable packages
UPGRADE_STAMP=/var/lib/apt/periodic/upgrade-stamp
if which unattended-upgrade >/dev/null 2>&1 && check_stamp $UPGRADE_STAMP $UnattendedUpgradeInterval; then
- if unattended-upgrade $XUUPOPT; then
+ if unattended-upgrade $XUUPOPT $LOCKFD>&-; then
update_stamp $UPGRADE_STAMP
debug_echo "unattended-upgrade (success)"
else