fix: fallback to use non mount helper in case of failed mount
This commit is contained in:
parent
a44fea0737
commit
8a05423153
4 changed files with 16 additions and 14 deletions
|
|
@ -34,9 +34,7 @@ const mount = async (config: BackendConfig, path: string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status === "error") {
|
if (status === "error") {
|
||||||
logger.debug(
|
logger.debug(`Trying to unmount any existing mounts at ${path} before mounting...`);
|
||||||
`Trying to unmount any existing mounts at ${path} before mounting...`,
|
|
||||||
);
|
|
||||||
await unmount(path);
|
await unmount(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,6 +56,9 @@ const mount = async (config: BackendConfig, path: string) => {
|
||||||
|
|
||||||
await executeMount(args);
|
await executeMount(args);
|
||||||
|
|
||||||
|
// Fallback with -i flag if the first mount fails using the mount helper
|
||||||
|
await executeMount(["-i", ...args]);
|
||||||
|
|
||||||
logger.info(`NFS volume at ${path} mounted successfully.`);
|
logger.info(`NFS volume at ${path} mounted successfully.`);
|
||||||
return { status: BACKEND_STATUS.mounted };
|
return { status: BACKEND_STATUS.mounted };
|
||||||
};
|
};
|
||||||
|
|
@ -120,9 +121,7 @@ const checkHealth = async (path: string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mount.fstype.startsWith("nfs")) {
|
if (!mount.fstype.startsWith("nfs")) {
|
||||||
throw new Error(
|
throw new Error(`Path ${path} is not mounted as NFS (found ${mount.fstype}).`);
|
||||||
`Path ${path} is not mounted as NFS (found ${mount.fstype}).`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`NFS volume at ${path} is healthy and mounted.`);
|
logger.debug(`NFS volume at ${path} is healthy and mounted.`);
|
||||||
|
|
@ -140,10 +139,7 @@ const checkHealth = async (path: string) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const makeNfsBackend = (
|
export const makeNfsBackend = (config: BackendConfig, path: string): VolumeBackend => ({
|
||||||
config: BackendConfig,
|
|
||||||
path: string,
|
|
||||||
): VolumeBackend => ({
|
|
||||||
mount: () => mount(config, path),
|
mount: () => mount(config, path),
|
||||||
unmount: () => unmount(path),
|
unmount: () => unmount(path),
|
||||||
checkHealth: () => checkHealth(path),
|
checkHealth: () => checkHealth(path),
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,9 @@ const mount = async (config: BackendConfig, path: string) => {
|
||||||
|
|
||||||
await executeMount(args);
|
await executeMount(args);
|
||||||
|
|
||||||
|
// Fallback with -i flag if the first mount fails using the mount helper
|
||||||
|
await executeMount(["-i", ...args]);
|
||||||
|
|
||||||
logger.info(`SMB volume at ${path} mounted successfully.`);
|
logger.info(`SMB volume at ${path} mounted successfully.`);
|
||||||
return { status: BACKEND_STATUS.mounted };
|
return { status: BACKEND_STATUS.mounted };
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,13 @@ export const executeMount = async (args: string[]): Promise<void> => {
|
||||||
const stderr = result.stderr.toString().trim();
|
const stderr = result.stderr.toString().trim();
|
||||||
|
|
||||||
if (result.exitCode === 0) {
|
if (result.exitCode === 0) {
|
||||||
logger.debug(stdout);
|
if (stdout) logger.debug(stdout);
|
||||||
logger.debug(stderr);
|
if (stderr) logger.debug(stderr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.warn(stdout);
|
if (stdout) logger.warn(stdout);
|
||||||
logger.warn(stderr);
|
if (stderr) logger.warn(stderr);
|
||||||
|
|
||||||
throw new Error(`Mount command failed with exit code ${result.exitCode}: ${stderr || stdout || "unknown error"}`);
|
throw new Error(`Mount command failed with exit code ${result.exitCode}: ${stderr || stdout || "unknown error"}`);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,9 @@ const mount = async (config: BackendConfig, path: string) => {
|
||||||
const args = ["-t", "davfs", "-o", options.join(","), source, path];
|
const args = ["-t", "davfs", "-o", options.join(","), source, path];
|
||||||
await executeMount(args);
|
await executeMount(args);
|
||||||
|
|
||||||
|
// Fallback with -i flag if the first mount fails using the mount helper
|
||||||
|
await executeMount(["-i", ...args]);
|
||||||
|
|
||||||
logger.info(`WebDAV volume at ${path} mounted successfully.`);
|
logger.info(`WebDAV volume at ${path} mounted successfully.`);
|
||||||
return { status: BACKEND_STATUS.mounted };
|
return { status: BACKEND_STATUS.mounted };
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue