replace debug() with our custom logger
mostly we want trace() and log(). trace() can be enabled whenever we want by flipping a flag and restarting box
This commit is contained in:
16
src/sftp.js
16
src/sftp.js
@@ -3,7 +3,7 @@ import assert from 'node:assert';
|
||||
import blobs from './blobs.js';
|
||||
import BoxError from './boxerror.js';
|
||||
import constants from './constants.js';
|
||||
import debugModule from 'debug';
|
||||
import logger from './logger.js';
|
||||
import docker from './docker.js';
|
||||
import hat from './hat.js';
|
||||
import infra from './infra_version.js';
|
||||
@@ -15,7 +15,7 @@ import services from './services.js';
|
||||
import shellModule from './shell.js';
|
||||
import volumes from './volumes.js';
|
||||
|
||||
const debug = debugModule('box:sftp');
|
||||
const { log, trace } = logger('sftp');
|
||||
const shell = shellModule('sftp');
|
||||
|
||||
const DEFAULT_MEMORY_LIMIT = 256 * 1024 * 1024;
|
||||
@@ -29,7 +29,7 @@ async function ensureKeys() {
|
||||
const privateKeyFile = path.join(paths.SFTP_KEYS_DIR, `ssh_host_${keyType}_key`);
|
||||
|
||||
if (!privateKey || !publicKey) {
|
||||
debug(`ensureSecrets: generating new sftp keys of type ${keyType}`);
|
||||
log(`ensureSecrets: generating new sftp keys of type ${keyType}`);
|
||||
safe.fs.unlinkSync(publicKeyFile);
|
||||
safe.fs.unlinkSync(privateKeyFile);
|
||||
const [error] = await safe(shell.spawn('ssh-keygen', ['-m', 'PEM', '-t', keyType, '-f', `${paths.SFTP_KEYS_DIR}/ssh_host_${keyType}_key`, '-q', '-N', ''], {}));
|
||||
@@ -48,7 +48,7 @@ async function ensureKeys() {
|
||||
async function start(existingInfra) {
|
||||
assert.strictEqual(typeof existingInfra, 'object');
|
||||
|
||||
debug('start: re-creating container');
|
||||
log('start: re-creating container');
|
||||
|
||||
const serviceConfig = await services.getServiceConfig('sftp');
|
||||
const image = infra.images.sftp;
|
||||
@@ -70,7 +70,7 @@ async function start(existingInfra) {
|
||||
const hostDir = await apps.getStorageDir(app), mountDir = `/mnt/app-${app.id}`; // see also sftp:userSearchSftp
|
||||
if (hostDir === null || !safe.fs.existsSync(hostDir)) { // this can fail if external mount does not have permissions for yellowtent user
|
||||
// do not create host path when cloudron is restoring. this will then create dir with root perms making restore logic fail
|
||||
debug(`Ignoring app data dir ${hostDir} for ${app.id} since it does not exist`);
|
||||
log(`Ignoring app data dir ${hostDir} for ${app.id} since it does not exist`);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ async function start(existingInfra) {
|
||||
if (mounts.isManagedProvider(volume.mountType)) continue; // skip managed volume. these are acessed via /mnt/volumes mount above
|
||||
|
||||
if (!safe.fs.existsSync(volume.hostPath)) {
|
||||
debug(`Ignoring volume host path ${volume.hostPath} since it does not exist`);
|
||||
log(`Ignoring volume host path ${volume.hostPath} since it does not exist`);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -118,11 +118,11 @@ async function start(existingInfra) {
|
||||
--label isCloudronManaged=true \
|
||||
${readOnly} -v /tmp -v /run ${image} ${cmd}`;
|
||||
|
||||
debug('startSftp: stopping and deleting previous sftp container');
|
||||
log('startSftp: stopping and deleting previous sftp container');
|
||||
await docker.stopContainer('sftp');
|
||||
await docker.deleteContainer('sftp');
|
||||
|
||||
debug('startSftp: starting sftp container');
|
||||
log('startSftp: starting sftp container');
|
||||
await shell.bash(runCmd, { encoding: 'utf8' });
|
||||
|
||||
if (existingInfra.version !== 'none' && existingInfra.images.sftp !== image) await docker.deleteImage(existingInfra.images.sftp);
|
||||
|
||||
Reference in New Issue
Block a user