more ESM cleanups

This commit is contained in:
Girish Ramakrishnan
2026-02-14 16:52:16 +01:00
parent e9f96593c3
commit b71e503a01
4 changed files with 42 additions and 49 deletions

70
box.js
View File

@@ -55,49 +55,43 @@ async function startServers() {
if (conf.enabled) await directoryServer.start();
}
async function main() {
const [error] = await safe(startServers());
if (error) return exitSync({ error, code: 1, message: 'Error starting servers' });
const [error] = await safe(startServers());
if (error) exitSync({ error, code: 1, message: 'Error starting servers' });
// require this here so that logging handler is already setup
process.on('SIGHUP', async function () {
debug('Received SIGHUP. Re-reading configs.');
const conf = await directoryServer.getConfig();
if (conf.enabled) await directoryServer.checkCertificate();
});
process.on('SIGHUP', async function () {
debug('Received SIGHUP. Re-reading configs.');
const conf = await directoryServer.getConfig();
if (conf.enabled) await directoryServer.checkCertificate();
});
process.on('SIGINT', async function () {
debug('Received SIGINT. Shutting down.');
process.on('SIGINT', async function () {
debug('Received SIGINT. Shutting down.');
await proxyAuth.stop();
await server.stop();
await directoryServer.stop();
await ldapServer.stop();
await oidcServer.stop();
await proxyAuth.stop();
await server.stop();
await directoryServer.stop();
await ldapServer.stop();
await oidcServer.stop();
setTimeout(() => {
debug('Shutdown complete');
process.exit();
}, 2000); // need to wait for the task processes to die
});
setTimeout(() => {
debug('Shutdown complete');
process.exit();
}, 2000); // need to wait for the task processes to die
});
process.on('SIGTERM', async function () {
debug('Received SIGTERM. Shutting down.');
process.on('SIGTERM', async function () {
debug('Received SIGTERM. Shutting down.');
await proxyAuth.stop();
await server.stop();
await directoryServer.stop();
await ldapServer.stop();
await oidcServer.stop();
await proxyAuth.stop();
await server.stop();
await directoryServer.stop();
await ldapServer.stop();
await oidcServer.stop();
setTimeout(() => {
debug('Shutdown complete');
process.exit();
}, 2000); // need to wait for the task processes to die
});
setTimeout(() => {
debug('Shutdown complete');
process.exit();
}, 2000); // need to wait for the task processes to die
});
process.on('uncaughtException', (error) => exitSync({ error, code: 1, message: 'From uncaughtException handler.' }));
}
main();
process.on('uncaughtException', (error) => exitSync({ error, code: 1, message: 'From uncaughtException handler.' }));

View File

@@ -30,6 +30,7 @@ import url from 'node:url';
import users from './users.js';
import groups from './groups.js';
import util from 'node:util';
import Provider from 'oidc-provider';
const debug = debugModule('box:oidcserver');
@@ -672,7 +673,6 @@ async function start() {
const fqdn = dns.fqdn(subdomain, domain);
debug(`start: create provider for ${fqdn} at ${ROUTE_PREFIX}`);
const Provider = (await import('oidc-provider')).default;
gOidcProvider = new Provider(`https://${fqdn}${ROUTE_PREFIX}`, configuration);
app.enable('trust proxy');

View File

@@ -1,19 +1,18 @@
#!/usr/bin/env node
// --check is used by run-tests to verify sudo access works.
// It must exit before loading the full module graph (which requires BOX_ENV).
import backuptask from '../backuptask.js';
import database from '../database.js';
import debugModule from 'debug';
import safe from 'safetydance';
const debug = debugModule('box:backupupload');
// --check is used by run-tests to verify sudo access works. Caller must set BOX_ENV (e.g. BOX_ENV=test).
if (process.argv[2] === '--check') {
console.log('OK');
process.exit(0);
}
const { default: backuptask } = await import('../backuptask.js');
const { default: database } = await import('../database.js');
const { default: debugModule } = await import('debug');
const { default: safe } = await import('safetydance');
const debug = debugModule('box:backupupload');
// Main process starts here
const remotePath = process.argv[2];
const format = process.argv[3];

View File

@@ -15,7 +15,7 @@ readarray -d '' scripts < <(find ${sudo_scripts_dir} -type f -print0)
declare -a missing_scripts=()
for script in "${scripts[@]}"; do
# sudo -k ignores a cached sudo session for the command
if [[ $(sudo -k -n "${script}" --check 2>/dev/null) != "OK" ]]; then
if [[ $(sudo -k -n env BOX_ENV=test "${script}" --check 2>/dev/null) != "OK" ]]; then
missing_scripts+=("${script}")
fi
done