volume: use mountpoint command to check if it is mounted

This commit is contained in:
Girish Ramakrishnan
2021-05-13 23:21:15 -07:00
parent c2fc978ffd
commit 8fc4a8abf7
+11 -2
View File
@@ -159,6 +159,14 @@ async function update(volume, mountType, mountOptions) {
async function getStatus(volume) {
assert.strictEqual(typeof volume, 'object');
if (volume.mountType === 'noop') {
if (safe.child_process.execSync(`mountpoint -q -- ${volume.hostPath}`, { encoding: 'utf8' })) {
return { state: 'active', message: 'Mounted' };
} else {
return { state: 'inactive', message: 'Not mounted' };
}
}
let output = safe.child_process.execSync(`systemctl show --value -p ActiveState $(systemd-escape -p --suffix=mount ${volume.hostPath})`, { encoding: 'utf8' });
let state = output ? output.trim() : '';
let message;
@@ -167,8 +175,9 @@ async function getStatus(volume) {
output = safe.child_process.execSync(`journalctl -u $(systemd-escape -p --suffix=mount ${volume.hostPath}) -n 10 --no-pager -o cat`, { encoding: 'utf8' });
if (output) {
const idx = output.split('\n').reverse().findIndex(l => l.includes('process exited'));
if (idx > 0) message = output[idx-1]; // the line before probably has the error
const lines = output.split('\n').reverse();
const idx = lines.findIndex(l => l.includes('process exited'));
if (idx > 0) message = lines[idx-1]; // the line before probably has the error
}
if (!message) message = `Could not determine failure reason: ${safe.error.message}`;
} else {