Mount data custom app data location specifically into sftp addon
Fixes #722
This commit is contained in:
82
src/sftp.js
82
src/sftp.js
@@ -1,10 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
startSftp: startSftp
|
||||
startSftp: startSftp,
|
||||
rebuild: rebuild
|
||||
};
|
||||
|
||||
var assert = require('assert'),
|
||||
var apps = require('./apps.js'),
|
||||
assert = require('assert'),
|
||||
async = require('async'),
|
||||
debug = require('debug')('box:sftp'),
|
||||
infra = require('./infra_version.js'),
|
||||
paths = require('./paths.js'),
|
||||
shell = require('./shell.js');
|
||||
@@ -13,28 +17,64 @@ function startSftp(existingInfra, callback) {
|
||||
assert.strictEqual(typeof existingInfra, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
if (existingInfra.version === infra.version && infra.images.sftp.tag === existingInfra.images.sftp.tag) return callback();
|
||||
|
||||
rebuild(callback);
|
||||
}
|
||||
|
||||
function rebuild(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
debug('rebuilding container');
|
||||
|
||||
const tag = infra.images.sftp.tag;
|
||||
const memoryLimit = 256;
|
||||
|
||||
if (existingInfra.version === infra.version && infra.images.sftp.tag === existingInfra.images.sftp.tag) return callback();
|
||||
apps.getAll(function (error, result) {
|
||||
if (error) return callback(error);
|
||||
|
||||
const cmd = `docker run --restart=always -d --name="sftp" \
|
||||
--hostname sftp \
|
||||
--net cloudron \
|
||||
--net-alias sftp \
|
||||
--log-driver syslog \
|
||||
--log-opt syslog-address=udp://127.0.0.1:2514 \
|
||||
--log-opt syslog-format=rfc5424 \
|
||||
--log-opt tag=sftp \
|
||||
-m ${memoryLimit}m \
|
||||
--memory-swap ${memoryLimit * 2}m \
|
||||
--dns 172.18.0.1 \
|
||||
--dns-search=. \
|
||||
-p 222:22 \
|
||||
-v "${paths.APPS_DATA_DIR}:/app/data" \
|
||||
-v "/etc/ssh:/etc/ssh:ro" \
|
||||
--label isCloudronManaged=true \
|
||||
--read-only -v /tmp -v /run "${tag}"`;
|
||||
let dataDirs = [];
|
||||
result.forEach(function (app) {
|
||||
if (!app.dataDir) return;
|
||||
|
||||
shell.exec('startSftp', cmd, callback);
|
||||
dataDirs.push({
|
||||
hostDir: app.dataDir,
|
||||
// /data is required since this is where the localstorage data would be in APPS_DATA_DIR
|
||||
mountDir: `/app/data/${app.id}/data`
|
||||
});
|
||||
});
|
||||
|
||||
debug('extra app volume mounts', dataDirs);
|
||||
|
||||
// ignore error if container not found (and fail later) so that this code works across restarts
|
||||
async.series([
|
||||
shell.exec.bind(null, 'stopSftpContainer', 'docker stop sftp || true'),
|
||||
shell.exec.bind(null, 'stopSftpContainer', 'docker rm -f sftp || true')
|
||||
], function (error) {
|
||||
if (error) debug('Failed to stop sftp container. Possibly not running.');
|
||||
|
||||
const extraAppDataVolumes = dataDirs.map(function (v) { return `-v "${v.hostDir}:${v.mountDir}"`; }).join(' ');
|
||||
|
||||
const cmd = `docker run --restart=always -d --name="sftp" \
|
||||
--hostname sftp \
|
||||
--net cloudron \
|
||||
--net-alias sftp \
|
||||
--log-driver syslog \
|
||||
--log-opt syslog-address=udp://127.0.0.1:2514 \
|
||||
--log-opt syslog-format=rfc5424 \
|
||||
--log-opt tag=sftp \
|
||||
-m ${memoryLimit}m \
|
||||
--memory-swap ${memoryLimit * 2}m \
|
||||
--dns 172.18.0.1 \
|
||||
--dns-search=. \
|
||||
-p 222:22 \
|
||||
-v "${paths.APPS_DATA_DIR}:/app/data" \
|
||||
${extraAppDataVolumes} \
|
||||
-v "/etc/ssh:/etc/ssh:ro" \
|
||||
--label isCloudronManaged=true \
|
||||
--read-only -v /tmp -v /run "${tag}"`;
|
||||
|
||||
shell.exec('startSftp', cmd, callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user