mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
fix: script remove docker volume (#2686)
* move sudo docker volume rm -f * fix: remove unnecessary function --------- Co-authored-by: vkamn <vk@amnezia.org>
This commit is contained in:
@@ -72,6 +72,16 @@ namespace
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString buildRemoveContainerScript(const amnezia::ScriptVars &vars, bool removeDataVolume)
|
||||||
|
{
|
||||||
|
QString script = SshSession::replaceVars(amnezia::scriptData(SharedScriptType::remove_container), vars);
|
||||||
|
if (removeDataVolume) {
|
||||||
|
script += QLatin1String("\nsudo docker volume rm -f $CONTAINER_NAME-data 2>/dev/null || true");
|
||||||
|
script = SshSession::replaceVars(script, vars);
|
||||||
|
}
|
||||||
|
return script;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InstallController::InstallController(SecureServersRepository *serversRepository,
|
InstallController::InstallController(SecureServersRepository *serversRepository,
|
||||||
@@ -120,14 +130,10 @@ ErrorCode InstallController::setupContainer(const ServerCredentials &credentials
|
|||||||
return e;
|
return e;
|
||||||
qDebug().noquote() << "InstallController::setupContainer prepareHostWorker finished";
|
qDebug().noquote() << "InstallController::setupContainer prepareHostWorker finished";
|
||||||
|
|
||||||
amnezia::ScriptVars removeContainerVars =
|
const amnezia::ScriptVars removeContainerVars =
|
||||||
amnezia::genBaseVars(credentials, container, QString(), QString());
|
amnezia::genBaseVars(credentials, container, QString(), QString());
|
||||||
if (!isUpdate) {
|
const bool removeDataVolume = !isUpdate && (container == DockerContainer::MtProxy || container == DockerContainer::Telemt);
|
||||||
removeContainerVars.append({ { "$REMOVE_CONTAINER_DATA", QStringLiteral("1") } });
|
sshSession.runScript(credentials, buildRemoveContainerScript(removeContainerVars, removeDataVolume));
|
||||||
}
|
|
||||||
sshSession.runScript(credentials,
|
|
||||||
sshSession.replaceVars(amnezia::scriptData(SharedScriptType::remove_container),
|
|
||||||
removeContainerVars));
|
|
||||||
qDebug().noquote() << "InstallController::setupContainer removeContainer finished";
|
qDebug().noquote() << "InstallController::setupContainer removeContainer finished";
|
||||||
|
|
||||||
qDebug().noquote() << "buildContainerWorker start";
|
qDebug().noquote() << "buildContainerWorker start";
|
||||||
@@ -1015,12 +1021,11 @@ ErrorCode InstallController::removeContainer(const QString &serverId, DockerCont
|
|||||||
return ErrorCode::InternalError;
|
return ErrorCode::InternalError;
|
||||||
}
|
}
|
||||||
SshSession sshSession(this);
|
SshSession sshSession(this);
|
||||||
amnezia::ScriptVars removeContainerVars =
|
const amnezia::ScriptVars removeContainerVars =
|
||||||
amnezia::genBaseVars(credentials, container, QString(), QString());
|
amnezia::genBaseVars(credentials, container, QString(), QString());
|
||||||
removeContainerVars.append({ { "$REMOVE_CONTAINER_DATA", QStringLiteral("1") } });
|
const bool removeDataVolume = (container == DockerContainer::MtProxy || container == DockerContainer::Telemt);
|
||||||
ErrorCode errorCode = sshSession.runScript(
|
ErrorCode errorCode =
|
||||||
credentials,
|
sshSession.runScript(credentials, buildRemoveContainerScript(removeContainerVars, removeDataVolume));
|
||||||
sshSession.replaceVars(amnezia::scriptData(SharedScriptType::remove_container), removeContainerVars));
|
|
||||||
|
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
QMap<DockerContainer, ContainerConfig> containers = adminConfig->containers;
|
QMap<DockerContainer, ContainerConfig> containers = adminConfig->containers;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
sudo docker stop $CONTAINER_NAME;\
|
sudo docker stop $CONTAINER_NAME;\
|
||||||
sudo docker rm -fv $CONTAINER_NAME;\
|
sudo docker rm -fv $CONTAINER_NAME;\
|
||||||
sudo docker rmi $CONTAINER_NAME;\
|
sudo docker rmi $CONTAINER_NAME;
|
||||||
test "$REMOVE_CONTAINER_DATA" = "1" && sudo docker volume rm -f ${CONTAINER_NAME}-data 2>/dev/null || true
|
|
||||||
|
|||||||
Reference in New Issue
Block a user