diff --git a/src/mounts.js b/src/mounts.js index 7a82e46ca..76ea47395 100644 --- a/src/mounts.js +++ b/src/mounts.js @@ -159,7 +159,7 @@ async function getStatus(mountType, hostPath) { async function tryAddMount(mount, options) { assert.strictEqual(typeof mount, 'object'); // { name, hostPath, mountType, mountOptions } - assert.strictEqual(typeof options, 'object'); // { timeout } + assert.strictEqual(typeof options, 'object'); // { timeout, skipCleanup } if (mount.mountType === 'mountpoint') return; @@ -175,6 +175,8 @@ async function tryAddMount(mount, options) { const [error] = await safe(shell.promises.sudo('addMount', [ ADD_MOUNT_CMD, renderMountFile(mount), options.timeout ], {})); if (error && error.code === 2) throw new BoxError(BoxError.MOUNT_ERROR, 'Failed to unmount existing mount'); // at this point, the old mount config is still there + if (options.skipCleanup) return; + const status = await getStatus(mount.mountType, mount.hostPath); if (status.state !== 'active') { // cleanup await removeMount(mount); diff --git a/src/platform.js b/src/platform.js index c3e9ae42a..ea45c2594 100644 --- a/src/platform.js +++ b/src/platform.js @@ -20,6 +20,7 @@ const apps = require('./apps.js'), services = require('./services.js'), shell = require('./shell.js'), tasks = require('./tasks.js'), + volumes = require('./volumes.js'), _ = require('underscore'); async function start(options) { @@ -47,10 +48,8 @@ async function start(options) { const error = locker.lock(locker.OP_PLATFORM_START); if (error) throw error; - if (existingInfra.version !== infra.version) { - await removeAllContainers(); - } - + if (existingInfra.version !== infra.version) await removeAllContainers(); + if (existingInfra.version === 'none') await volumes.mountAll(); // when restoring, mount all volumes await markApps(existingInfra, options); // mark app state before we start addons. this gives the db import logic a chance to mark an app as errored await services.startServices(existingInfra); await fs.promises.writeFile(paths.INFRA_VERSION_FILE, JSON.stringify(infra, null, 4)); diff --git a/src/volumes.js b/src/volumes.js index 59e9571a1..813153ba3 100644 --- a/src/volumes.js +++ b/src/volumes.js @@ -6,7 +6,9 @@ exports = module.exports = { del, list, getStatus, - removePrivateFields + removePrivateFields, + + mountAll }; const assert = require('assert'), @@ -159,3 +161,11 @@ async function del(volume, auditSource) { await collectd.removeProfile(volume.id); } + +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 + } +} \ No newline at end of file