Closed alberpilot closed 10 months ago
The rest of the unchecked points will be approached in a next iteration.
In CentOS 8 I could not reproduce the error. I investigated that the yum lock is generated by the PackageKit tool. After installing and using it, I could not get the yum lock error. I tested launching several processes that use the yum package manager and I could not get the yum lock error. Instead, I get the warning message:
Waiting for process with pid 7684 to finish.
But this does not terminate the execution process, it waits until the other process is finished and then, it continues the execution normally, so there is no error in this case.
In CentOS 7 I could reproduce the error with and without the PackageKit tool. The test consisted of the following:
yum update
command and not confirm the operation.yum install zip
command.
The error generated is the expected:
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum
Memory : 100 M RSS (324 MB VSZ)
Started: Mon Oct 30 11:55:08 2023 - 00:13 ago
With this, it is necessary to create an installCommon_yumInstall
function, similar to the installCommon_aptInstall
function, and make the necessary changes.
I encountered a problem in fetching the lock message of the yum command. When yum is locked, the yum install
command generates the message but the script is blocked in that command because yum is not finished yet.
I tried to redirect the output and/or send the process to the background but they do not work properly.
Another possible workaround was to set a timeout to the yum install
command, but this alternative was discarded because large installation packages would be interrupted and slow internet connections would not allow Wazuh to install due to this timeout.
I changed the workaround for the issue. In the case of RPM, the yum lock is created in the /var/run/yum.pid
file, so checking the existence of this file avoids fetching the lock message generated in the yum install
command.
Is necessary to:
I notice that, when yum is locked, the yum list installed
command used in the yumInstallList
function is blocked because of the lock, so it is necessary to adapt the mentioned function too and check if this behavior is reproduced in DEB systems.
[root@centos7 vagrant]# yum list installed
Loaded plugins: fastestmirror
Existing lock /var/run/yum.pid: another copy is running as pid 4421.
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum
Memory : 104 M RSS (429 MB VSZ)
Started: Tue Oct 31 14:01:04 2023 - 00:07 ago
State : Running, pid: 4421
The YUM change has been made and validated:
I have tested that, when installing a packaging and removing another one, the lock error message is generated:
In one terminal:
The following packages will be upgraded:
libx11-6
1 upgraded, 107 newly installed, 0 to remove and 147 not upgraded.
Need to get 21.9 MB of archives.
After this operation, 89.8 MB of additional disk space will be used.
Do you want to continue? [Y/n]
And then, in another
root@ubuntu22:/home/vagrant# apt-get remove zip
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 2318 (apt-get)
N: Be aware that removing the lock file is not a solution and may break your system.
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
With this, it is tested that when removing a Wazuh installation and using the APT package manager in another process, the lock error is generated, so it is necessary to handle it.
However, the apt list --installed
does not show this lock message when another process is using APT, so it is not necessary to change this.
I found a bug in the Installation Assistant related to this: it seems that the Wazuh components are uninstalled successfully, but the lock error is being generated (false green). An issue has been reported here.
root@ubuntu22:/home/vagrant# bash wazuh-install.sh -u
02/11/2023 10:12:00 INFO: Starting Wazuh installation assistant. Wazuh version: 4.8.0
02/11/2023 10:12:00 INFO: Verbose logging redirected to /var/log/wazuh-install.log
02/11/2023 10:12:02 INFO: Wazuh manager not found in the system so it was not uninstalled.
02/11/2023 10:12:02 INFO: Filebeat not found in the system so it was not uninstalled.
02/11/2023 10:12:02 INFO: Wazuh dashboard not found in the system so it was not uninstalled.
02/11/2023 10:12:02 INFO: Removing Wazuh indexer.
02/11/2023 10:12:02 INFO: Wazuh indexer removed.
root@ubuntu22:/home/vagrant# apt list --installed | grep wazuh
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
wazuh-indexer/now 4.8.0-40800 amd64 [installed,local]
root@ubuntu22:/home/vagrant# cat /var/log/wazuh-install.log
02/11/2023 10:15:16 DEBUG: Checking root permissions.
02/11/2023 10:15:16 INFO: Starting Wazuh installation assistant. Wazuh version: 4.8.0
02/11/2023 10:15:16 INFO: Verbose logging redirected to /var/log/wazuh-install.log
02/11/2023 10:15:16 DEBUG: APT package manager will be used.
02/11/2023 10:15:16 DEBUG: Checking system distribution.
02/11/2023 10:15:16 DEBUG: Detected distribution name: ubuntu
02/11/2023 10:15:16 DEBUG: Detected distribution version: 22
02/11/2023 10:15:16 DEBUG: Checking Wazuh installation.
02/11/2023 10:15:17 INFO: Wazuh manager not found in the system so it was not uninstalled.
02/11/2023 10:15:17 INFO: Filebeat not found in the system so it was not uninstalled.
02/11/2023 10:15:17 INFO: Wazuh dashboard not found in the system so it was not uninstalled.
02/11/2023 10:15:17 INFO: Removing Wazuh indexer.
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 8230 (apt-get)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
02/11/2023 10:15:17 INFO: Wazuh indexer removed.
02/11/2023 10:15:17 DEBUG: Removing GPG key from system.
02/11/2023 10:15:17 INFO: Wazuh GPG key not found in the system
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 8230 (apt-get)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
To solve this, it is necessary to split the aptInstall
function into two functions, one that installs the packages, and the other to check the APT lock. This last function will be also used in the installCommon_rollBack
function.
This function will use the fuser /var/lib/dpkg/lock
command. This command verifies if the lock file of APT is being used for another process.
The following code shows how the Wazuh installation assistant manages a situation where another process is running
apt
, locking it and not allowing to use it to Wazuh installation assistant:https://github.com/wazuh/wazuh-packages/blob/c875a1986c1bc30bfb079f10d024ece160c9a74a/unattended_installer/install_functions/installCommon.sh#L71-L92
Tasks
i
variable name toattemps
or similar (more descriptive).