diff --git a/server/lib/diagnostic/prosody.ts b/server/lib/diagnostic/prosody.ts index 71f79912..8290a336 100644 --- a/server/lib/diagnostic/prosody.ts +++ b/server/lib/diagnostic/prosody.ts @@ -15,7 +15,7 @@ export async function diagProsody (test: string, options: RegisterServerOptions) return result } - // FIXME: these tests should also be in testProsodyCorrectlyRunning. Remove from here? + // FIXME: these tests are very similar to tests in testProsodyCorrectlyRunning. Remove from here? // Testing the prosody config file. try { const filePath = await getProsodyConfigPath(options) diff --git a/server/lib/prosody/ctl.ts b/server/lib/prosody/ctl.ts index 5ba022e4..f1ff0bd4 100644 --- a/server/lib/prosody/ctl.ts +++ b/server/lib/prosody/ctl.ts @@ -1,13 +1,14 @@ -import { getProsodyFilePaths, writeProsodyConfig } from './config' +import { getProsodyConfigContent, getProsodyConfigPath, getProsodyFilePaths, writeProsodyConfig } from './config' import * as fs from 'fs' import * as child_process from 'child_process' -interface ProsodyRunning { - ok: boolean - messages: string[] +interface ProsodyCtlResult { + code: number | null + stdout: string + sterr: string + message: string } - -async function prosodyCtl (options: RegisterServerOptions, command: string, failOnError: boolean): Promise { +async function prosodyCtl (options: RegisterServerOptions, command: string): Promise { const logger = options.peertubeHelpers.logger logger.debug('Calling prosodyCtl with command ' + command) @@ -15,9 +16,10 @@ async function prosodyCtl (options: RegisterServerOptions, command: string, fail if (!/^\w+$/.test(command)) { throw new Error(`Invalid prosodyctl command '${command}'`) } - return new Promise((resolve, reject) => { + return new Promise((resolve) => { let d: string = '' let e: string = '' + let m: string = '' const spawned = child_process.spawn('prosodyctl', [ '--config', filePaths.config, @@ -31,26 +33,33 @@ async function prosodyCtl (options: RegisterServerOptions, command: string, fail }) spawned.stdout.on('data', (data) => { d += data as string + m += data as string }) spawned.stderr.on('data', (data) => { options.peertubeHelpers.logger.error(`Spawned command ${command} has errors: ${data as string}`) e += data as string + m += data as string }) - spawned.on('close', (code) => { - if (code !== 0 && failOnError) { - reject(e) - } else { - if (e !== '') { d += e } - resolve(d) - } + spawned.on('exit', (code) => { + resolve({ + code: code, + stdout: d, + sterr: e, + message: m + }) }) }) } async function getProsodyAbout (options: RegisterServerOptions): Promise { - return prosodyCtl(options, 'about', true) + const ctl = await prosodyCtl(options, 'about') + return ctl.message } +interface ProsodyRunning { + ok: boolean + messages: string[] +} async function testProsodyRunning (options: RegisterServerOptions): Promise { const { peertubeHelpers } = options const logger = peertubeHelpers.logger @@ -72,6 +81,12 @@ async function testProsodyRunning (options: RegisterServerOptions): Promise