Skip to content

Commit

Permalink
Added checkAptLock function
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcr01 committed Dec 14, 2023
1 parent 751916d commit aae2491
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 14 additions & 0 deletions unattended_installer/common_functions/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
# License (version 2) as published by the FSF - Free Software
# Foundation.

function common_checkAptLock() {

attempt=0
seconds=30
max_attempts=10

while fuser "${apt_lockfile}" >/dev/null 2>&1 && [ "${attempt}" -lt "${max_attempts}" ]; do
attempt=$((attempt+1))
common_logger "Another process is using APT. Waiting for it to release the lock. Next retry in ${seconds} seconds (${attempt}/${max_attempts})"
sleep "${seconds}"
done

}

function common_logger() {

now=$(date +'%d/%m/%Y %H:%M:%S')
Expand Down
10 changes: 5 additions & 5 deletions unattended_installer/install_functions/installCommon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function installCommon_aptInstall() {
fi

command="DEBIAN_FRONTEND=noninteractive apt-get install ${installer} -y -q"
installCommon_checkAptLock
common_checkAptLock

if [ "${attempt}" -ne "${max_attempts}" ]; then
apt_output=$(eval "${command} 2>&1")
Expand Down Expand Up @@ -551,7 +551,7 @@ function installCommon_rollBack() {
manager_installed=$(yum list installed 2>/dev/null | grep wazuh-manager)
fi
elif [ "${sys_type}" == "apt-get" ]; then
installCommon_checkAptLock
common_checkAptLock
eval "apt-get remove --purge wazuh-manager -y ${debug}"
manager_installed=$(apt list --installed 2>/dev/null | grep wazuh-manager)
fi
Expand All @@ -577,7 +577,7 @@ function installCommon_rollBack() {
indexer_installed=$(yum list installed 2>/dev/null | grep wazuh-indexer)
fi
elif [ "${sys_type}" == "apt-get" ]; then
installCommon_checkAptLock
common_checkAptLock
eval "apt-get remove --purge wazuh-indexer -y ${debug}"
indexer_installed=$(apt list --installed 2>/dev/null | grep wazuh-indexer)
fi
Expand All @@ -604,7 +604,7 @@ function installCommon_rollBack() {
filebeat_installed=$(yum list installed 2>/dev/null | grep filebeat)
fi
elif [ "${sys_type}" == "apt-get" ]; then
installCommon_checkAptLock
common_checkAptLock
eval "apt-get remove --purge filebeat -y ${debug}"
filebeat_installed=$(apt list --installed 2>/dev/null | grep filebeat)
fi
Expand All @@ -631,7 +631,7 @@ function installCommon_rollBack() {
dashboard_installed=$(yum list installed 2>/dev/null | grep wazuh-dashboard)
fi
elif [ "${sys_type}" == "apt-get" ]; then
installCommon_checkAptLock
common_checkAptLock
eval "apt-get remove --purge wazuh-dashboard -y ${debug}"
dashboard_installed=$(apt list --installed 2>/dev/null | grep wazuh-dashboard)
fi
Expand Down

0 comments on commit aae2491

Please sign in to comment.