Files
runner-images/images/linux/scripts/base/apt-mock.sh
Sergey Dolin ec9befb26a Workaround for apt db locked by WALinuxAgent v2 (#2000)
* retry apt if lock is held by other process

* Increase timeout and change grep string
2020-11-11 14:01:41 +03:00

33 lines
553 B
Bash

#!/bin/bash -e
# A temporary workaround for https://github.com/Azure/azure-linux-extensions/issues/1238
prefix=/usr/local/bin
for tool in apt apt-get apt-fast;do
real_tool=`which $tool`
cat >$prefix/$tool <<EOT
#!/bin/sh
i=1
while [ \$i -le 30 ];do
err=\$(mktemp)
$real_tool "\$@" 2>\$err
result=\$?
if [ \$result -eq 0 ];then
break
fi
grep -q 'Could not get lock' \$err
held=\$?
if [ \$held -ne 0 ];then
break
fi
cat \$err >&2
sleep 5
echo "...retry \$i"
i=\$((i + 1))
done
EOT
chmod +x $prefix/$tool
done