fixup various shell usage

This commit is contained in:
Girish Ramakrishnan
2024-02-28 18:47:53 +01:00
parent 07527fe2b1
commit 3316dd1f42
4 changed files with 47 additions and 21 deletions

View File

@@ -31,6 +31,7 @@ const assert = require('assert'),
docker = require('./docker.js'),
domains = require('./domains.js'),
eventlog = require('./eventlog.js'),
fs = require('fs'),
hat = require('./hat.js'),
infra = require('./infra_version.js'),
Location = require('./location.js'),
@@ -153,7 +154,9 @@ async function configureMail(mailFqdn, mailDomain, serviceConfig) {
const mailCertFilePath = `${paths.MAIL_CONFIG_DIR}/tls_cert.pem`;
const mailKeyFilePath = `${paths.MAIL_CONFIG_DIR}/tls_key.pem`;
const [copyError] = await safe(shell.exec('configureMail', `cp ${paths.DHPARAMS_FILE} ${dhparamsFilePath}`, {}));
const [readError, dhparams] = await safe(fs.promises.readFile(paths.DHPARAMS_FILE));
if (readError) throw new BoxError(BoxError.FS_ERROR, `Could not read dhparams: ${readError.message}`);
const [copyError] = await safe(fs.promises.writeFile(dhparamsFilePath, dhparams));
if (copyError) throw new BoxError(BoxError.FS_ERROR, `Could not copy dhparams: ${copyError.message}`);
if (!safe.fs.writeFileSync(mailCertFilePath, certificate.cert)) throw new BoxError(BoxError.FS_ERROR, `Could not create cert file: ${safe.error.message}`);
if (!safe.fs.writeFileSync(mailKeyFilePath, certificate.key)) throw new BoxError(BoxError.FS_ERROR, `Could not create key file: ${safe.error.message}`);
@@ -161,8 +164,9 @@ async function configureMail(mailFqdn, mailDomain, serviceConfig) {
// if the 'yellowtent' user of OS and the 'cloudron' user of mail container don't match, the keys become inaccessible by mail code
if (!safe.fs.chmodSync(mailKeyFilePath, 0o644)) throw new BoxError(BoxError.FS_ERROR, `Could not chmod key file: ${safe.error.message}`);
await safe(shell.exec('stopMail', 'docker stop mail', {})); // ignore error
await safe(shell.exec('removeMail', 'docker rm -f mail', {})); // ignore error
debug('configureMail: stopping and deleting previous mail container');
await docker.stopContainer('mail');
await docker.deleteContainer('mail');
const allowInbound = await createMailConfig(mailFqdn);
@@ -191,7 +195,8 @@ async function configureMail(mailFqdn, mailDomain, serviceConfig) {
--label isCloudronManaged=true \
${readOnly} -v /run -v /tmp ${image} ${cmd}`;
await shell.exec('startMail', runCmd, { shell: '/bin/bash' });
debug('configureMail: starting mail container');
await shell.exec('configureMail', runCmd, { shell: '/bin/bash' });
}
async function restart() {