mounts: always return message when getting status

This commit is contained in:
Girish Ramakrishnan
2025-11-05 16:38:11 +01:00
parent 2ea7847d4f
commit de84b5113c
5 changed files with 11 additions and 10 deletions
+1 -1
View File
@@ -470,7 +470,7 @@ async function remount(site) {
async function getStatus(site) {
assert.strictEqual(typeof site, 'object');
return await storageApi(site).getStatus(site.config);
return await storageApi(site).getStatus(site.config); // { state, message }
}
async function ensureMounted(site) {
+6 -5
View File
@@ -189,15 +189,18 @@ async function getStatus(mountType, hostPath) {
assert.strictEqual(typeof mountType, 'string');
assert.strictEqual(typeof hostPath, 'string');
if (mountType === exports.MOUNT_TYPE_FILESYSTEM) return { state: 'active', message: 'Mounted' };
if (mountType === exports.MOUNT_TYPE_FILESYSTEM) {
const exists = safe.fs.existsSync(hostPath);
return { state: exists ? 'active' : 'inactive', message: exists ? '' : `${hostPath} not found: ${safe.error.message}` };
}
const [error] = await safe(shell.spawn('mountpoint', [ '-q', '--', hostPath ], { timeout: 5000, encoding: 'utf8' }));
const state = error ? 'inactive' : 'active';
if (mountType === 'mountpoint') return { state, message: state === 'active' ? 'Mounted' : 'Not mounted' };
if (mountType === 'mountpoint') return { state, message: state === 'active' ? '' : 'Not mounted' };
// we used to rely on "systemctl show -p ActiveState" output before but some mounts like sshfs.fuse show the status as "active" event though the mount commant failed (on ubuntu 18)
let message;
let message = '';
if (state !== 'active') { // find why it failed
const unitName = await shell.spawn('systemd-escape', ['-p', '--suffix=mount', hostPath], { encoding: 'utf8' });
@@ -221,8 +224,6 @@ async function getStatus(mountType, hostPath) {
if (end !== -1) message = lines.slice(start, end+1).map(line => line['MESSAGE']).join('\n');
}
if (!message) message = `Could not determine mount failure reason. ${safe.error ? safe.error.message : ''}`;
} else {
message = 'Mounted';
}
return { state, message };
+2 -2
View File
@@ -70,9 +70,9 @@ async function getStatus(config) {
let hostPath;
if (mounts.isManagedProvider(config._provider)) {
hostPath = config._managedMountPath;
} else if (config._provider === 'mountpoint') {
} else if (config._provider === mounts.MOUNT_TYPE_MOUNTPOINT) {
hostPath = config.mountPoint;
} else if (config._provider === 'filesystem') {
} else if (config._provider === mounts.MOUNT_TYPE_FILESYSTEM) {
hostPath = config.backupDir;
}
+1 -1
View File
@@ -64,7 +64,7 @@ async function getStatus(apiConfig) {
const query = { prefix: path.join(apiConfig.prefix, 'snapshot'), autoPaginate: false, maxResults: 1 };
const [listError] = await safe(bucket.getFiles(query));
if (listError) return { state: 'inactive', message: `Failed to get files: ${listError.message}` };
return { state: 'active' };
return { state: 'active', message: '' };
}
async function upload(apiConfig, remotePath) {
+1 -1
View File
@@ -172,7 +172,7 @@ async function getStatus(apiConfig) {
const [listError] = await safe(s3.listObjectsV2(listParams));
if (listError) return { status: 'inactive', message: `Error listing objects. ${formatError(listError)}` };
return { state: 'active' };
return { state: 'active', message: '' };
}
async function upload(apiConfig, remotePath) {