mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #571 from YunoHost/wait_for_dpkg_lock
[enh] Wait for dpkg lock to be free
This commit is contained in:
commit
b3c5f44518
2 changed files with 27 additions and 1 deletions
|
@ -1,3 +1,26 @@
|
|||
# Check if apt is free to use, or wait, until timeout.
|
||||
#
|
||||
# [internal]
|
||||
#
|
||||
# usage: ynh_wait_dpkg_free
|
||||
ynh_wait_dpkg_free() {
|
||||
local try
|
||||
# With seq 1 17, timeout will be almost 30 minutes
|
||||
for try in `seq 1 17`
|
||||
do
|
||||
# Check if /var/lib/dpkg/lock is used by another process
|
||||
if sudo lsof /var/lib/dpkg/lock > /dev/null
|
||||
then
|
||||
echo "apt is already in use..."
|
||||
# Sleep an exponential time at each round
|
||||
sleep $(( try * try ))
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
echo "apt still used, but timeout reached !"
|
||||
}
|
||||
|
||||
# Check either a package is installed or not
|
||||
#
|
||||
# example: ynh_package_is_installed 'yunohost' && echo "ok"
|
||||
|
@ -5,6 +28,7 @@
|
|||
# usage: ynh_package_is_installed name
|
||||
# | arg: name - the package name to check
|
||||
ynh_package_is_installed() {
|
||||
ynh_wait_dpkg_free
|
||||
dpkg-query -W -f '${Status}' "$1" 2>/dev/null \
|
||||
| grep -c "ok installed" &>/dev/null
|
||||
}
|
||||
|
@ -30,6 +54,7 @@ ynh_package_version() {
|
|||
#
|
||||
# usage: ynh_apt update
|
||||
ynh_apt() {
|
||||
ynh_wait_dpkg_free
|
||||
DEBIAN_FRONTEND=noninteractive sudo apt-get -y $@
|
||||
}
|
||||
|
||||
|
@ -105,6 +130,7 @@ ynh_package_install_from_equivs () {
|
|||
# Create a fake deb package with equivs-build and the given control file
|
||||
# Install the fake package without its dependencies with dpkg
|
||||
# Install missing dependencies with ynh_package_install
|
||||
ynh_wait_dpkg_free
|
||||
(cp "$controlfile" "${TMPDIR}/control" && cd "$TMPDIR" \
|
||||
&& equivs-build ./control 1>/dev/null \
|
||||
&& sudo dpkg --force-depends \
|
||||
|
|
2
debian/control
vendored
2
debian/control
vendored
|
@ -26,7 +26,7 @@ Depends: ${python:Depends}, ${misc:Depends}
|
|||
, metronome
|
||||
, rspamd (>= 1.6.0), redis-server, opendkim-tools
|
||||
, haveged, fake-hwclock
|
||||
, equivs
|
||||
, equivs, lsof
|
||||
Recommends: yunohost-admin
|
||||
, openssh-server, ntp, inetutils-ping | iputils-ping
|
||||
, bash-completion, rsyslog, etckeeper
|
||||
|
|
Loading…
Add table
Reference in a new issue