diff --git a/src/mounts.js b/src/mounts.js index 4146f3f16..084d1105f 100644 --- a/src/mounts.js +++ b/src/mounts.js @@ -97,7 +97,7 @@ function isManagedProvider(provider) { async function renderMountFile(mount) { assert.strictEqual(typeof mount, 'object'); - const { name, hostPath, mountType, mountOptions } = mount; + const { description, hostPath, mountType, mountOptions } = mount; let options, what, type, dependsOn; switch (mountType) { @@ -154,7 +154,7 @@ async function renderMountFile(mount) { return; } - return ejs.render(SYSTEMD_MOUNT_EJS, { name, what, where: hostPath, options, type, dependsOn }); + return ejs.render(SYSTEMD_MOUNT_EJS, { description, what, where: hostPath, options, type, dependsOn }); } async function removeMount(mount) { @@ -220,10 +220,10 @@ async function getStatus(mountType, hostPath) { } async function tryAddMount(mount, options) { - assert.strictEqual(typeof mount, 'object'); // { name, hostPath, mountType, mountOptions } + assert.strictEqual(typeof mount, 'object'); // { description, hostPath, mountType, mountOptions } assert.strictEqual(typeof options, 'object'); // { timeout, skipCleanup } - if (mount.mountType === 'mountpoint' || mount.mountType === exports.MOUNT_TYPE_FILESYSTEM) return; + assert(isManagedProvider(mount.mountType)); if (constants.TEST) return; @@ -240,13 +240,11 @@ async function tryAddMount(mount, options) { } } -async function remount(mount) { - assert.strictEqual(typeof mount, 'object'); // { name, hostPath, mountType, mountOptions } - - if (mount.mountType === 'mountpoint' || mount.mountType === exports.MOUNT_TYPE_FILESYSTEM) return; +async function remount(hostPath) { + assert.strictEqual(typeof hostPath, 'string'); if (constants.TEST) return; - const [error] = await safe(shell.sudo([ REMOUNT_MOUNT_CMD, mount.hostPath ], {})); + const [error] = await safe(shell.sudo([ REMOUNT_MOUNT_CMD, hostPath ], {})); if (error && error.code === 2) throw new BoxError(BoxError.MOUNT_ERROR, 'Failed to remount existing mount'); // at this point, the old mount config is still there } diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index c3b81db88..9c8231d9c 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -241,7 +241,7 @@ async function setupManagedMount(apiConfig, hostPath) { debug(`setupManagedMount: setting up mount at ${hostPath} with ${apiConfig.provider}`); const newMount = { - name: path.basename(hostPath), + description: `Cloudron Managed Mount`, hostPath, mountType: apiConfig.provider, mountOptions: apiConfig.mountOptions @@ -257,14 +257,8 @@ async function setup(apiConfig) { debug('setup: removing old storage configuration'); if (!mounts.isManagedProvider(apiConfig.provider)) return; - const oldMountObject = { - name: 'backup', - hostPath: paths.MANAGED_BACKUP_MOUNT_DIR, - mountType: apiConfig.provider, - mountOptions: apiConfig.mountOptions // must have already been validated - }; - await safe(mounts.removeMount(oldMountObject), { debug }); // ignore error + await safe(mounts.removeMount(paths.MANAGED_BACKUP_MOUNT_DIR), { debug }); // ignore error debug('setup: setting up new storage configuration'); await setupManagedMount(apiConfig, paths.MANAGED_BACKUP_MOUNT_DIR); @@ -274,14 +268,8 @@ async function teardown(apiConfig) { assert.strictEqual(typeof apiConfig, 'object'); if (!mounts.isManagedProvider(apiConfig.provider)) return; - const mountObject = { - name: 'backup', - hostPath: paths.MANAGED_BACKUP_MOUNT_DIR, - mountType: apiConfig.provider, - mountOptions: apiConfig.mountOptions - }; - await safe(mounts.removeMount(mountObject), { debug }); // ignore error + await safe(mounts.removeMount(paths.MANAGED_BACKUP_MOUNT_DIR), { debug }); // ignore error } async function testConfig(apiConfig) { @@ -333,7 +321,7 @@ async function testConfig(apiConfig) { throw new BoxError(BoxError.BAD_FIELD, `Unable to remove test file as 'yellowtent' user in ${rootPath}: ${safe.error.message}. Check dir/mount permissions`); } - if (testMountObject) await mounts.removeMount(testMountObject); + if (testMountObject) await mounts.removeMount('/mnt/backup-storage-validation'); } function removePrivateFields(apiConfig) { diff --git a/src/systemd-mount.ejs b/src/systemd-mount.ejs index 08432456d..5bcc71bb4 100644 --- a/src/systemd-mount.ejs +++ b/src/systemd-mount.ejs @@ -1,5 +1,5 @@ [Unit] -Description=<%= name %> +Description=<%= description %> <% if ( type === 'cifs' || type === 'nfs' || type === 'fuse.sshfs' ) { %> Requires=<%= dependsOn %> After=<%= dependsOn %> diff --git a/src/volumes.js b/src/volumes.js index a238c36dc..77a49c6e1 100644 --- a/src/volumes.js +++ b/src/volumes.js @@ -92,7 +92,7 @@ async function add(volume, auditSource) { hostPath = mountOptions.hostPath; } else { hostPath = path.join(paths.VOLUMES_MOUNT_DIR, id); - const mount = { name, hostPath, mountType, mountOptions }; + const mount = { description: name, hostPath, mountType, mountOptions }; await mounts.tryAddMount(mount, { timeout: 10 }); // 10 seconds } @@ -160,12 +160,12 @@ async function update(id, mountOptions, auditSource) { } const hostPath = path.join(paths.VOLUMES_MOUNT_DIR, id); - const mount = { name, hostPath, mountType: mountType, mountOptions }; + const mount = { description: name, hostPath, mountType, mountOptions }; // first try to mount at /mnt/volumes/-validation const testMount = Object.assign({}, mount, { hostPath: `${hostPath}-validation` }); await mounts.tryAddMount(testMount, { timeout: 10 }); // 10 seconds - await mounts.removeMount(testMount); + await mounts.removeMount(testMount.hostPath); // update the mount await mounts.tryAddMount(mount, { timeout: 10 }); // 10 seconds @@ -204,7 +204,7 @@ async function del(volume, auditSource) { if (volume.mountType === mounts.MOUNT_TYPE_MOUNTPOINT || volume.mountType === mounts.MOUNT_TYPE_FILESYSTEM) { safe(services.rebuildService('sftp', auditSource), { debug }); } else { - await safe(mounts.removeMount(volume)); + await safe(mounts.removeMount(volume.hostPath)); } } @@ -212,6 +212,7 @@ async function mountAll() { debug('mountAll: mouting all volumes'); for (const volume of await list()) { - await mounts.tryAddMount(volume, { timeout: 10, skipCleanup: true }); // have to wait to avoid race with apptask + const mount = { description: volume.name, ...volume }; + await mounts.tryAddMount(mount, { timeout: 10, skipCleanup: true }); // have to wait to avoid race with apptask } }