From ecf5b7c68f766ffdb16d9b675a27d0ce617e1781 Mon Sep 17 00:00:00 2001 From: lunardunno <126363523+lunardunno@users.noreply.github.com> Date: Tue, 18 Mar 2025 16:12:20 +0400 Subject: [PATCH] Checking sudo docker and status of the service Checking presence Sudo and Docker on the server. Checking the status of the Docker service. --- client/core/controllers/serverController.cpp | 4 +++- client/core/defs.h | 1 + client/core/errorstrings.cpp | 1 + client/server_scripts/install_docker.sh | 6 +++--- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/client/core/controllers/serverController.cpp b/client/core/controllers/serverController.cpp index 05283195..b29e1aa5 100644 --- a/client/core/controllers/serverController.cpp +++ b/client/core/controllers/serverController.cpp @@ -409,8 +409,10 @@ ErrorCode ServerController::installDockerWorker(const ServerCredentials &credent qDebug().noquote() << "ServerController::installDockerWorker" << stdOut; if (stdOut.contains("lock")) return ErrorCode::ServerPacketManagerError; - if (stdOut.contains("command not found")) + if (stdOut.contains("sudo:") && stdOut.contains("not found")) return ErrorCode::ServerDockerFailedError; + if (stdOut.contains("Failed docker status")) + return ErrorCode::ServerDockerStatusNotActive; return error; } diff --git a/client/core/defs.h b/client/core/defs.h index e073d030..7e90d15b 100644 --- a/client/core/defs.h +++ b/client/core/defs.h @@ -58,6 +58,7 @@ namespace amnezia ServerUserDirectoryNotAccessible = 208, ServerUserNotAllowedInSudoers = 209, ServerUserPasswordRequired = 210, + ServerDockerStatusNotActive = 211, // Ssh connection errors SshRequestDeniedError = 300, diff --git a/client/core/errorstrings.cpp b/client/core/errorstrings.cpp index a3d54601..33dc3908 100644 --- a/client/core/errorstrings.cpp +++ b/client/core/errorstrings.cpp @@ -26,6 +26,7 @@ QString errorString(ErrorCode code) { case(ErrorCode::ServerUserDirectoryNotAccessible): errorMessage = QObject::tr("The server user's home directory is not accessible"); break; case(ErrorCode::ServerUserNotAllowedInSudoers): errorMessage = QObject::tr("Action not allowed in sudoers"); break; case(ErrorCode::ServerUserPasswordRequired): errorMessage = QObject::tr("The user's password is required"); break; + case(ErrorCode::ServerDockerStatusNotActive): errorMessage = QObject::tr("Docker service status is not active"); break; // Libssh errors case(ErrorCode::SshRequestDeniedError): errorMessage = QObject::tr("SSH request was denied"); break; diff --git a/client/server_scripts/install_docker.sh b/client/server_scripts/install_docker.sh index abbfbedf..2a9cba93 100644 --- a/client/server_scripts/install_docker.sh +++ b/client/server_scripts/install_docker.sh @@ -3,7 +3,7 @@ elif which dnf > /dev/null 2>&1; then pm=$(which dnf); silent_inst="-yq install" elif which yum > /dev/null 2>&1; then pm=$(which yum); silent_inst="-y -q install"; check_pkgs="-y -q check-update"; wh_pkg="--assumeno install --setopt=tsflags=test"; docker_pkg="docker"; check_srv="docker"; dist="centos";\ elif which pacman > /dev/null 2>&1; then pm=$(which pacman); silent_inst="-S --noconfirm --noprogressbar --quiet"; check_pkgs="-Sup"; wh_pkg="-Sp"; docker_pkg="docker"; check_srv="docker"; dist="archlinux";\ else echo "Packet manager not found"; exit 1; fi;\ -echo "Dist: $dist, Packet manager: $pm, Install command: $silent_inst, Check pkgs command: $check_pkgs, What pkg command: $wh_pkg, Docker pkg: $docker_pkg", Check service: $check_srv";\ +echo "Dist: $dist, Packet manager: $pm, Install command: $silent_inst, Check pkgs command: $check_pkgs, What pkg command: $wh_pkg, Docker pkg: $docker_pkg, Check service: $check_srv";\ if [ "$dist" = "debian" ]; then export DEBIAN_FRONTEND=noninteractive; fi;\ echo $LANG | grep -qE '^(en_US.UTF-8|C.UTF-8|C)$' || export LC_ALL=C;\ if ! command -v sudo > /dev/null 2>&1; then $pm $check_pkgs; $pm $silent_inst sudo; fi;\ @@ -19,6 +19,6 @@ fi;\ if [ "$(systemctl is-active $check_srv)" != "active" ]; then \ sudo $pm $check_pkgs; sudo $pm $silent_inst $docker_pkg;\ sleep 5; sudo systemctl start $check_srv; sleep 5;\ + if [ "$(systemctl is-active $check_srv)" != "active" ]; then echo "Failed docker status"; fi;\ fi;\ -if ! command -v sudo > /dev/null 2>&1; then echo "Failed to install sudo, command not found"; exit 1; fi;\ -docker --version +sudo docker --version