volume: use mountpoint command to check if it is mounted
This commit is contained in:
+11
-2
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user