diff --git a/admin/app/services/system_service.ts b/admin/app/services/system_service.ts index 517a4bc..08fddf2 100644 --- a/admin/app/services/system_service.ts +++ b/admin/app/services/system_service.ts @@ -129,18 +129,25 @@ export class SystemService { si.time(), ]) - const diskInfoRawString = await getFile( - path.join(process.cwd(), SystemService.diskInfoFile), - 'string' - ) + let diskInfo: NomadDiskInfoRaw | undefined + let disk: NomadDiskInfo[] = [] - const diskInfo = ( - diskInfoRawString - ? JSON.parse(diskInfoRawString.toString()) - : { diskLayout: { blockdevices: [] }, fsSize: [] } - ) as NomadDiskInfoRaw + try { + const diskInfoRawString = await getFile( + path.join(process.cwd(), SystemService.diskInfoFile), + 'string' + ) - const disk = this.calculateDiskUsage(diskInfo) + diskInfo = ( + diskInfoRawString + ? JSON.parse(diskInfoRawString.toString()) + : { diskLayout: { blockdevices: [] }, fsSize: [] } + ) as NomadDiskInfoRaw + + disk = this.calculateDiskUsage(diskInfo) + } catch (error) { + logger.error('Error reading disk info file:', error) + } return { cpu, @@ -164,7 +171,7 @@ export class SystemService { */ private async _syncContainersWithDatabase() { try { - const allServices = await Service.all(); + const allServices = await Service.all() const serviceStatusList = await this.dockerService.getServicesStatus() for (const service of allServices) { @@ -189,7 +196,6 @@ export class SystemService { } } } - } catch (error) { logger.error('Error syncing containers with database:', error) } diff --git a/install/install_nomad.sh b/install/install_nomad.sh index dc18a30..5b86f4b 100644 --- a/install/install_nomad.sh +++ b/install/install_nomad.sh @@ -237,6 +237,12 @@ create_nomad_directory(){ sudo touch "${NOMAD_DIR}/storage/logs/admin.log" } +create_disk_info_file() { + # Disk info file MUST be created before the admin container starts. + # Otherwise, Docker will assume we meant to mount a directory and will create an empty directory at the mount point + echo '{}' > /tmp/nomad-disk-info.json +} + download_management_compose_file() { local compose_file_path="${NOMAD_DIR}/compose.yml"