diff options
author | Julian Andres Klode <jak@debian.org> | 2017-04-28 11:11:53 +0200 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2017-05-05 14:49:30 +0200 |
commit | 82579d3ef511d553d374150b18e6ad6f3cfd872b (patch) | |
tree | 6abcc71ba58fec599cf146aa3b16c1e4a85cb584 /debian | |
parent | 5c83b304dc507574b85bae20050a95fd9aab0018 (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)
(cherry picked from commit 820b469f0648eaa63356a812cd96ca8c4af6ac71)
Diffstat (limited to 'debian')
-rw-r--r-- | debian/apt.systemd.daily | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/debian/apt.systemd.daily b/debian/apt.systemd.daily index a8d98494b..22cbbded6 100644 --- 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 |