remove spaces in ensure_packages_installed, add xfs migration logging
This commit is contained in:
parent
73cb1ca67e
commit
49f8d46b45
|
@ -30,8 +30,8 @@ async def ensure_packages_installed(
|
||||||
return True
|
return True
|
||||||
|
|
||||||
update_cmd = (
|
update_cmd = (
|
||||||
"apt-get update "
|
"apt-get update"
|
||||||
"-y "
|
"-y"
|
||||||
"--no-install-recommends"
|
"--no-install-recommends"
|
||||||
)
|
)
|
||||||
return_code, stdout, stderr = await utils.async_run_command(
|
return_code, stdout, stderr = await utils.async_run_command(
|
||||||
|
@ -44,12 +44,12 @@ async def ensure_packages_installed(
|
||||||
return False
|
return False
|
||||||
|
|
||||||
install_cmd = (
|
install_cmd = (
|
||||||
"apt-get install "
|
"apt-get install"
|
||||||
"-y "
|
"-y"
|
||||||
"--no-install-recommends "
|
"--no-install-recommends"
|
||||||
"--assume-yes "
|
"--assume-yes"
|
||||||
"-o Dpkg::Options::='--force-confdef' " # Default to existing config
|
"-o Dpkg::Options::='--force-confdef'" # Default to existing config
|
||||||
"-o Dpkg::Options::='--force-confold' " # Keep existing config
|
"-o Dpkg::Options::='--force-confold'" # Keep existing config
|
||||||
f"{' '.join(packages_to_install)}"
|
f"{' '.join(packages_to_install)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
20
lib/xfs.py
20
lib/xfs.py
|
@ -6,6 +6,7 @@ from lib import networking
|
||||||
from lib import get_specs
|
from lib import get_specs
|
||||||
from lib import utils
|
from lib import utils
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
@ -66,8 +67,10 @@ def get_to_use_storage_values(max_free_space):
|
||||||
def migrate():
|
def migrate():
|
||||||
docker_xfs_state = validate_docker_xfs()
|
docker_xfs_state = validate_docker_xfs()
|
||||||
if docker_xfs_state == "skip":
|
if docker_xfs_state == "skip":
|
||||||
|
migrate_log("skipping migration")
|
||||||
return
|
return
|
||||||
elif docker_xfs_state == "valid":
|
elif docker_xfs_state == "valid":
|
||||||
|
migrate_log("migration succeeded")
|
||||||
return 'success'
|
return 'success'
|
||||||
|
|
||||||
packages_available = asyncio.run(ensure_packages_installed.ensure_packages_installed(
|
packages_available = asyncio.run(ensure_packages_installed.ensure_packages_installed(
|
||||||
|
@ -75,15 +78,18 @@ def migrate():
|
||||||
))
|
))
|
||||||
|
|
||||||
if not packages_available:
|
if not packages_available:
|
||||||
|
migrate_log("packages missing")
|
||||||
return 'packages-missing'
|
return 'packages-missing'
|
||||||
|
|
||||||
root_device = get_specs.get_root_device()
|
root_device = get_specs.get_root_device()
|
||||||
if not root_device:
|
if not root_device:
|
||||||
|
migrate_log("not supported boot device")
|
||||||
return "not-supported-boot-device"
|
return "not-supported-boot-device"
|
||||||
|
|
||||||
device_name = os.path.basename(root_device).split('p')[0].rstrip('0123456789')
|
device_name = os.path.basename(root_device).split('p')[0].rstrip('0123456789')
|
||||||
|
|
||||||
if get_specs.is_usb_device(device_name):
|
if get_specs.is_usb_device(device_name):
|
||||||
|
migrate_log("not supported boot device")
|
||||||
return "not-supported-boot-device"
|
return "not-supported-boot-device"
|
||||||
|
|
||||||
log.info("Starting migration to xfs")
|
log.info("Starting migration to xfs")
|
||||||
|
@ -93,17 +99,19 @@ def migrate():
|
||||||
try:
|
try:
|
||||||
os.remove(DOCKER_DATA_IMG)
|
os.remove(DOCKER_DATA_IMG)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error while trying to remove {DOCKER_DATA_IMG}: {e}")
|
migrate_log("Failed to remove DOCKER_DATA_IMG")
|
||||||
return "failure"
|
return "failure"
|
||||||
|
|
||||||
max_free_space = utils.get_free_space_mb('/') + utils.get_directory_size_mb(DOCKER_ROOT)
|
max_free_space = utils.get_free_space_mb('/') + utils.get_directory_size_mb(DOCKER_ROOT)
|
||||||
|
|
||||||
leave_free_space, min_xfs_size = get_to_use_storage_values(max_free_space)
|
leave_free_space, min_xfs_size = get_to_use_storage_values(max_free_space)
|
||||||
if leave_free_space == None:
|
if leave_free_space == None:
|
||||||
|
migrate_log("can't get free space")
|
||||||
return "failure"
|
return "failure"
|
||||||
|
|
||||||
data_img_size = int(max_free_space - leave_free_space)
|
data_img_size = int(max_free_space - leave_free_space)
|
||||||
if data_img_size < min_xfs_size:
|
if data_img_size < min_xfs_size:
|
||||||
|
migrate_log("not enought free space")
|
||||||
return 'not-enough-space'
|
return 'not-enough-space'
|
||||||
|
|
||||||
docker_config_success = False
|
docker_config_success = False
|
||||||
|
@ -126,6 +134,7 @@ def migrate():
|
||||||
if code==0:
|
if code==0:
|
||||||
return 'success'
|
return 'success'
|
||||||
else:
|
else:
|
||||||
|
migrate_log("failed to migrate v1")
|
||||||
configure_docker_daemon(remove=True)
|
configure_docker_daemon(remove=True)
|
||||||
configure_fstab(remove=True)
|
configure_fstab(remove=True)
|
||||||
return 'failure'
|
return 'failure'
|
||||||
|
@ -138,7 +147,16 @@ def migrate():
|
||||||
os.remove(DOCKER_DATA_IMG)
|
os.remove(DOCKER_DATA_IMG)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
migrate_log("failed to migrate v2")
|
||||||
return 'failure'
|
return 'failure'
|
||||||
|
|
||||||
|
def migrate_log(msg):
|
||||||
|
log_file_path = "/opt/clore-hosting/migrate-log.txt"
|
||||||
|
os.makedirs(os.path.dirname(log_file_path), exist_ok=True)
|
||||||
|
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
log_message = f"{current_time} | {msg}\n"
|
||||||
|
with open(log_file_path, "a") as log_file:
|
||||||
|
log_file.write(log_message)
|
||||||
|
|
||||||
def validate_docker_xfs():
|
def validate_docker_xfs():
|
||||||
code_root, stdout_root, stderr_root = utils.run_command("df -T /")
|
code_root, stdout_root, stderr_root = utils.run_command("df -T /")
|
||||||
|
|
Loading…
Reference in New Issue