From 63112df21a04eae1ecda3b4376016a4824271e11 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 14 Apr 2021 17:48:46 +0200 Subject: [PATCH] Fix prosody exec call. --- server/lib/prosody/ctl.ts | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/server/lib/prosody/ctl.ts b/server/lib/prosody/ctl.ts index 8bb55e43..53de5c7c 100644 --- a/server/lib/prosody/ctl.ts +++ b/server/lib/prosody/ctl.ts @@ -1,10 +1,7 @@ import { getProsodyFilePaths, writeProsodyConfig } from './config' import * as fs from 'fs' -import * as util from 'util' import * as child_process from 'child_process' -const exec = util.promisify(child_process.exec) - interface ProsodyRunning { ok: boolean messages: string[] @@ -125,16 +122,39 @@ async function ensureProsodyRunning (options: RegisterServerOptions): Promise { + return new Promise((resolve) => { + setTimeout(resolve, ms) + }) + } + logger.info('Waiting for the prosody process to launch') + let count: number = 0 + let processStarted: boolean = false + while (!processStarted && count < 5) { + count++ + await sleep(500) + logger.info('Verifying prosody is launched') + try { + const status = await prosodyCtl(options, 'status', true) + logger.info(`Prosody status: ${status}`) + processStarted = true + } catch (error) { + logger.warn(`Prosody status: ${error as string}`) + } + } + if (!processStarted) { + logger.error('It seems that the Prosody process is not up') + } else { + logger.info('Prosody is running') + } } async function ensureProsodyNotRunning (options: RegisterServerOptions): Promise {