added a check for the existence of the container before installing it
This commit is contained in:
parent
2fdab4c196
commit
b2fd94d20e
4 changed files with 31 additions and 0 deletions
|
@ -32,6 +32,7 @@ enum ErrorCode
|
||||||
ServerContainerMissingError,
|
ServerContainerMissingError,
|
||||||
ServerDockerFailedError,
|
ServerDockerFailedError,
|
||||||
ServerCancelInstallation,
|
ServerCancelInstallation,
|
||||||
|
ServerContainerAlreadyInstalledError,
|
||||||
|
|
||||||
// Ssh connection errors
|
// Ssh connection errors
|
||||||
SshSocketError, SshTimeoutError, SshProtocolError,
|
SshSocketError, SshTimeoutError, SshProtocolError,
|
||||||
|
|
|
@ -16,6 +16,7 @@ QString errorString(ErrorCode code){
|
||||||
case(ServerContainerMissingError): return QObject::tr("Server error: Docker container missing");
|
case(ServerContainerMissingError): return QObject::tr("Server error: Docker container missing");
|
||||||
case(ServerDockerFailedError): return QObject::tr("Server error: Docker failed");
|
case(ServerDockerFailedError): return QObject::tr("Server error: Docker failed");
|
||||||
case(ServerCancelInstallation): return QObject::tr("Installation canceled by user");
|
case(ServerCancelInstallation): return QObject::tr("Installation canceled by user");
|
||||||
|
case(ServerContainerAlreadyInstalledError): return QObject::tr("Container already installed");
|
||||||
|
|
||||||
// Ssh connection errors
|
// Ssh connection errors
|
||||||
case(SshSocketError): return QObject::tr("Ssh connection error");
|
case(SshSocketError): return QObject::tr("Ssh connection error");
|
||||||
|
|
|
@ -415,6 +415,9 @@ ErrorCode ServerController::setupContainer(const ServerCredentials &credentials,
|
||||||
//qDebug().noquote() << QJsonDocument(config).toJson();
|
//qDebug().noquote() << QJsonDocument(config).toJson();
|
||||||
ErrorCode e = ErrorCode::NoError;
|
ErrorCode e = ErrorCode::NoError;
|
||||||
|
|
||||||
|
e = isContainerAlreadyInstalled(credentials, container);
|
||||||
|
if (e) return e;
|
||||||
|
|
||||||
e = installDockerWorker(credentials, container);
|
e = installDockerWorker(credentials, container);
|
||||||
if (e) return e;
|
if (e) return e;
|
||||||
qDebug().noquote() << "ServerController::setupContainer installDockerWorker finished";
|
qDebug().noquote() << "ServerController::setupContainer installDockerWorker finished";
|
||||||
|
@ -856,3 +859,28 @@ QString ServerController::replaceVars(const QString &script, const Vars &vars)
|
||||||
//qDebug().noquote() << script;
|
//qDebug().noquote() << script;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorCode ServerController::isContainerAlreadyInstalled(const ServerCredentials &credentials, DockerContainer container)
|
||||||
|
{
|
||||||
|
QString stdOut;
|
||||||
|
auto cbReadStdOut = [&](const QString &data, QSharedPointer<QSsh::SshRemoteProcess> proc) {
|
||||||
|
stdOut += data + "\n";
|
||||||
|
};
|
||||||
|
auto cbReadStdErr = [&](const QString &data, QSharedPointer<QSsh::SshRemoteProcess> ) {
|
||||||
|
stdOut += data + "\n";
|
||||||
|
};
|
||||||
|
|
||||||
|
QString script = QString("sudo docker ps | grep %1").arg(ContainerProps::containerToString(container));
|
||||||
|
|
||||||
|
ErrorCode errorCode = runScript(credentials,
|
||||||
|
replaceVars(script, genVarsForScript(credentials, container)), cbReadStdOut, cbReadStdErr);
|
||||||
|
|
||||||
|
if (errorCode != ErrorCode::NoError) {
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stdOut.isEmpty()) {
|
||||||
|
return ErrorCode::ServerContainerAlreadyInstalledError;
|
||||||
|
}
|
||||||
|
return ErrorCode::NoError;
|
||||||
|
}
|
||||||
|
|
|
@ -82,6 +82,7 @@ private:
|
||||||
ErrorCode runContainerWorker(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config);
|
ErrorCode runContainerWorker(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config);
|
||||||
ErrorCode configureContainerWorker(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config);
|
ErrorCode configureContainerWorker(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config);
|
||||||
ErrorCode startupContainerWorker(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config = QJsonObject());
|
ErrorCode startupContainerWorker(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config = QJsonObject());
|
||||||
|
ErrorCode isContainerAlreadyInstalled(const ServerCredentials &credentials, DockerContainer container);
|
||||||
|
|
||||||
std::shared_ptr<Settings> m_settings;
|
std::shared_ptr<Settings> m_settings;
|
||||||
std::shared_ptr<VpnConfigurator> m_configurator;
|
std::shared_ptr<VpnConfigurator> m_configurator;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue