diff --git a/src/backupsites.js b/src/backupsites.js index fad4999da..4875864c9 100644 --- a/src/backupsites.js +++ b/src/backupsites.js @@ -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) { diff --git a/src/mounts.js b/src/mounts.js index 68c1acadb..ab9e4b931 100644 --- a/src/mounts.js +++ b/src/mounts.js @@ -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 }; diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index 109c7fbfd..f07b301d4 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -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; } diff --git a/src/storage/gcs.js b/src/storage/gcs.js index 82186ec6c..0fb884510 100644 --- a/src/storage/gcs.js +++ b/src/storage/gcs.js @@ -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) { diff --git a/src/storage/s3.js b/src/storage/s3.js index b62bcbd39..44839ff15 100644 --- a/src/storage/s3.js +++ b/src/storage/s3.js @@ -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) {