Fix for server busy check (#287)

Fix for server busy check
This commit is contained in:
pokamest 2023-08-16 08:08:08 -07:00 committed by GitHub
parent c7d2a3ffd4
commit ba3ef98d1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 14 deletions

View file

@ -2,11 +2,11 @@ cmake_minimum_required(VERSION 3.25.0 FATAL_ERROR)
set(PROJECT AmneziaVPN) set(PROJECT AmneziaVPN)
project(${PROJECT} VERSION 3.0.9.0 project(${PROJECT} VERSION 3.0.9.1
DESCRIPTION "AmneziaVPN" DESCRIPTION "AmneziaVPN"
HOMEPAGE_URL "https://amnezia.org/" HOMEPAGE_URL "https://amnezia.org/"
) )
set(RELEASE_DATE "2023-07-15") set(RELEASE_DATE "2023-08-16")
set(APP_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH}) set(APP_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH})
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

View file

@ -56,7 +56,7 @@
setQuitOnLastWindowClosed(false); setQuitOnLastWindowClosed(false);
// Fix config file permissions // Fix config file permissions
#ifdef Q_OS_LINUX && !defined(Q_OS_ANDROID) #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
{ {
QSettings s(ORGANIZATION_NAME, APPLICATION_NAME); QSettings s(ORGANIZATION_NAME, APPLICATION_NAME);
s.setValue("permFixed", true); s.setValue("permFixed", true);

View file

@ -138,7 +138,7 @@ android {
resConfig "en" resConfig "en"
minSdkVersion = 24 minSdkVersion = 24
targetSdkVersion = 34 targetSdkVersion = 34
versionCode 31 // Change to a higher number versionCode 32 // Change to a higher number
versionName "3.0.9" // Change to a higher number versionName "3.0.9" // Change to a higher number
javaCompileOptions.annotationProcessorOptions.arguments = [ javaCompileOptions.annotationProcessorOptions.arguments = [

View file

@ -33,6 +33,7 @@ enum ErrorCode
ServerDockerFailedError, ServerDockerFailedError,
ServerCancelInstallation, ServerCancelInstallation,
ServerUserNotInSudo, ServerUserNotInSudo,
ServerPacketManagerError,
// Ssh connection errors // Ssh connection errors
SshRequsetDeniedError, SshInterruptedError, SshInternalError, SshRequsetDeniedError, SshInterruptedError, SshInternalError,

View file

@ -369,6 +369,7 @@ ErrorCode ServerController::installDockerWorker(const ServerCredentials &credent
genVarsForScript(credentials)), cbReadStdOut, cbReadStdErr); genVarsForScript(credentials)), cbReadStdOut, cbReadStdErr);
qDebug().noquote() << "ServerController::installDockerWorker" << stdOut; qDebug().noquote() << "ServerController::installDockerWorker" << stdOut;
if (stdOut.contains("lock")) return ErrorCode::ServerPacketManagerError;
if (stdOut.contains("command not found")) return ErrorCode::ServerDockerFailedError; if (stdOut.contains("command not found")) return ErrorCode::ServerDockerFailedError;
return error; return error;
@ -697,7 +698,8 @@ ErrorCode ServerController::isServerDpkgBusy(const ServerCredentials &credential
QFutureWatcher<ErrorCode> watcher; QFutureWatcher<ErrorCode> watcher;
QFuture<ErrorCode> future = QtConcurrent::run([this, &stdOut, &cbReadStdOut, &cbReadStdErr, &credentials]() { QFuture<ErrorCode> future = QtConcurrent::run([this, &stdOut, &cbReadStdOut, &cbReadStdErr, &credentials]() {
do { // max 100 attempts
for (int i = 0; i < 100; ++i) {
if (m_cancelInstallation) { if (m_cancelInstallation) {
return ErrorCode::ServerCancelInstallation; return ErrorCode::ServerCancelInstallation;
} }
@ -705,12 +707,22 @@ ErrorCode ServerController::isServerDpkgBusy(const ServerCredentials &credential
runScript(credentials, runScript(credentials,
replaceVars(amnezia::scriptData(SharedScriptType::check_server_is_busy), replaceVars(amnezia::scriptData(SharedScriptType::check_server_is_busy),
genVarsForScript(credentials)), cbReadStdOut, cbReadStdErr); genVarsForScript(credentials)), cbReadStdOut, cbReadStdErr);
if (!stdOut.isEmpty() || stdOut.contains("Unable to acquire the dpkg frontend lock")) {
emit serverIsBusy(true); // if 'fuser' is not installed, skip check
QThread::msleep(1000); if (stdOut.contains("Not installed")) return ErrorCode::NoError;
}
} while (!stdOut.isEmpty()); if (stdOut.isEmpty()) {
return ErrorCode::NoError; return ErrorCode::NoError;
}
else {
#ifdef MZ_DEBUG
qDebug().noquote() << stdOut;
#endif
emit serverIsBusy(true);
QThread::msleep(5000);
}
}
return ErrorCode::ServerPacketManagerError;
}); });
QEventLoop wait; QEventLoop wait;

View file

@ -1,4 +1,5 @@
pm_apt="/usr/bin/apt-get";\ if which apt-get > /dev/null 2>&1; then LOCK_FILE="/var/lib/dpkg/lock-frontend";\
if [[ -f "$pm_apt" ]]; then pm=$pm_apt; else exit; fi;\ elif which dnf > /dev/null 2>&1; then LOCK_FILE="/var/run/dnf.pid";\
if [[ ! -f "/usr/bin/sudo" ]]; then $pm update -y -q; $pm install -y -q sudo; fi;\ elif which yum > /dev/null 2>&1; then LOCK_FILE="/var/run/yum.pid";\
sudo fuser /var/lib/dpkg/lock-frontend else echo "Packet manager not found"; echo "Internal error"; exit 1; fi;\
if command -v fuser > /dev/null 2>&1; then sudo fuser $LOCK_FILE; else echo "Not installed"; fi