Add code for cloudron-support to check and fix docker version

This commit is contained in:
Johannes Zellner
2024-10-17 12:41:33 +02:00
parent df5ba25010
commit fac5d3c07b

View File

@@ -24,6 +24,7 @@ readonly HELP_MESSAGE="
--patch Apply a patch from git. WARNING: Do not use unless you know what you are doing!
--recreate-containers Deletes all existing containers and recreates them without loss of data
--recreate-docker Deletes docker storage (containers and images) and recreates it without loss of data
--fix-docker-version Ensures the correct docker version is installed
--send-diagnostics Collects server diagnostics and uploads it to ${PASTEBIN}
--troubleshoot Dashboard down? Run tests to identify the potential problem
--owner-login Login as owner
@@ -421,6 +422,23 @@ function check_docker() {
success "docker is running"
}
function check_docker_version() {
expected_docker_version="$(sed -ne 's/readonly docker_version="\(.*\)"/\1/p' /home/yellowtent/box/scripts/installer.sh)"
if command -v docker &> /dev/null; then
current_docker_version="$(docker version --format {{.Client.Version}})"
else
current_docker_version="<not found>"
fi
if [[ "${current_docker_version}" != "${expected_docker_version}" ]]; then
fail "docker version is incorrect. Expecting ${expected_docker_version}. Got ${current_docker_version}."
echo "Run cloudron-support --fix-docker-version"
exit 1
fi
success "docker version is correct"
}
function check_node() {
expected_node_version="$(sed -ne 's/readonly node_version=\(.*\)/\1/p' /home/yellowtent/box/scripts/installer.sh)"
if command -v node &> /dev/null; then
@@ -546,6 +564,7 @@ function troubleshoot() {
check_node
check_ipv6
check_docker
check_docker_version
check_host_mysql
check_nginx # requires mysql to be checked
check_dashboard_cert
@@ -686,6 +705,24 @@ function recreate_docker() {
rm "${stagefile}"
}
function fix_docker_version() {
ubuntu_codename=$(lsb_release -cs)
ubuntu_version=$(lsb_release -rs)
docker_version="$(sed -ne 's/readonly docker_version="\(.*\)"/\1/p' /home/yellowtent/box/scripts/installer.sh)"
containerd_version="$(sed -ne 's/readonly containerd_version="\(.*\)"/\1/p' /home/yellowtent/box/scripts/installer.sh)"
echo "downloading docker ${docker_version}"
# copied from installer.sh
curl --fail -sL "https://download.docker.com/linux/ubuntu/dists/${ubuntu_codename}/pool/stable/amd64/containerd.io_${containerd_version}_amd64.deb" -o /tmp/containerd.deb
curl --fail -sL "https://download.docker.com/linux/ubuntu/dists/${ubuntu_codename}/pool/stable/amd64/docker-ce-cli_${docker_version}-1~ubuntu.${ubuntu_version}~${ubuntu_codename}_amd64.deb" -o /tmp/docker-ce-cli.deb
curl --fail -sL "https://download.docker.com/linux/ubuntu/dists/${ubuntu_codename}/pool/stable/amd64/docker-ce_${docker_version}-1~ubuntu.${ubuntu_version}~${ubuntu_codename}_amd64.deb" -o /tmp/docker.deb
echo "installing docker"
apt install -y --allow-downgrades /tmp/containerd.deb /tmp/docker-ce-cli.deb /tmp/docker.deb
rm /tmp/containerd.deb /tmp/docker-ce-cli.deb /tmp/docker.deb
}
function apply_patch() {
commit_id="$1"
patch_file="/tmp/${commit_id}.patch"
@@ -720,7 +757,7 @@ function apply_patch() {
check_disk_space
args=$(getopt -o "" -l "admin-login,disable-dnssec,enable-ssh,enable-remote-access,help,owner-login,patch:,recreate-containers,recreate-docker,send-diagnostics,unbound-use-external-dns,troubleshoot" -n "$0" -- "$@")
args=$(getopt -o "" -l "admin-login,disable-dnssec,enable-ssh,enable-remote-access,help,owner-login,patch:,recreate-containers,recreate-docker,fix-docker-version,send-diagnostics,unbound-use-external-dns,troubleshoot" -n "$0" -- "$@")
eval set -- "${args}"
while true; do
@@ -739,6 +776,7 @@ while true; do
--unbound-use-external-dns) unbound_use_external_dns; exit 0;;
--recreate-containers) recreate_containers; exit 0;;
--recreate-docker) recreate_docker; exit 0;;
--fix-docker-version) fix_docker_version; exit 0;;
--patch) apply_patch "$2"; exit 0;;
--help) break;;
--) break;;