2024-05-23 09:42:14 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
2024-06-12 08:53:14 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 OPNA2608 <opna2608@protonmail.com>
|
2024-05-23 09:42:14 +00:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-01-11 00:29:33 +00:00
|
|
|
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
2023-04-13 15:00:34 +00:00
|
|
|
import { getProsodyConfig, getProsodyFilePaths, writeProsodyConfig } from './config'
|
2021-05-12 12:59:52 +00:00
|
|
|
import { startProsodyLogRotate, stopProsodyLogRotate } from './logrotate'
|
2023-04-13 15:00:34 +00:00
|
|
|
import {
|
2023-05-31 10:11:02 +00:00
|
|
|
ensureProsodyCertificates,
|
|
|
|
startProsodyCertificatesRenewCheck,
|
|
|
|
stopProsodyCertificatesRenewCheck,
|
|
|
|
missingSelfSignedCertificates
|
2023-04-13 15:00:34 +00:00
|
|
|
} from './certificates'
|
2022-08-23 18:34:03 +00:00
|
|
|
import { disableProxyRoute, enableProxyRoute } from '../routers/webchat'
|
2023-04-14 09:25:29 +00:00
|
|
|
import { fixRoomSubject } from './fix-room-subject'
|
2021-04-14 13:26:00 +00:00
|
|
|
import * as fs from 'fs'
|
2021-04-14 14:14:56 +00:00
|
|
|
import * as child_process from 'child_process'
|
2023-05-19 10:52:52 +00:00
|
|
|
import { disableLuaUnboundIfNeeded, prosodyDebuggerOptions } from '../../lib/debug'
|
2021-04-13 15:13:41 +00:00
|
|
|
|
2022-11-15 15:07:12 +00:00
|
|
|
async function _ensureWorkingDir (
|
|
|
|
options: RegisterServerOptions,
|
|
|
|
workingDir: string,
|
2022-11-15 15:30:24 +00:00
|
|
|
dataDir: string,
|
2023-04-13 16:22:03 +00:00
|
|
|
certsDir: string | undefined,
|
|
|
|
certsDirIsCustom: boolean,
|
2022-11-15 15:30:24 +00:00
|
|
|
appImageExtractPath: string
|
2022-11-15 15:07:12 +00:00
|
|
|
): Promise<string> {
|
|
|
|
const logger = options.peertubeHelpers.logger
|
2022-11-15 15:30:24 +00:00
|
|
|
logger.debug('Calling _ensureworkingDir')
|
2022-11-15 15:07:12 +00:00
|
|
|
|
|
|
|
if (!fs.existsSync(workingDir)) {
|
|
|
|
logger.info(`The working dir ${workingDir} does not exists, trying to create it`)
|
|
|
|
await fs.promises.mkdir(workingDir)
|
|
|
|
logger.debug(`Working dir ${workingDir} was created`)
|
|
|
|
}
|
|
|
|
logger.debug(`Testing write access on ${workingDir}`)
|
|
|
|
await fs.promises.access(workingDir, fs.constants.W_OK) // will throw an error if no access
|
|
|
|
logger.debug(`Write access ok on ${workingDir}`)
|
|
|
|
|
|
|
|
if (!fs.existsSync(dataDir)) {
|
|
|
|
logger.info(`The data dir ${dataDir} does not exists, trying to create it`)
|
|
|
|
await fs.promises.mkdir(dataDir)
|
2022-11-15 15:30:24 +00:00
|
|
|
logger.debug(`data dir ${dataDir} was created`)
|
|
|
|
}
|
|
|
|
|
2023-04-13 16:22:03 +00:00
|
|
|
if (certsDir && !certsDirIsCustom && !fs.existsSync(certsDir)) {
|
2022-12-06 16:19:53 +00:00
|
|
|
// Certificates dir for Prosody.
|
|
|
|
// Note: not used yet, but we create the directory to avoid errors in prosody logs.
|
|
|
|
logger.info(`The certs dir ${certsDir} does not exists, trying to create it`)
|
|
|
|
await fs.promises.mkdir(certsDir)
|
|
|
|
logger.debug(`certs dir ${certsDir} was created`)
|
|
|
|
}
|
|
|
|
|
2022-11-15 15:30:24 +00:00
|
|
|
if (!fs.existsSync(appImageExtractPath)) {
|
|
|
|
logger.info(`The appImageExtractPath dir ${appImageExtractPath} does not exists, trying to create it`)
|
|
|
|
await fs.promises.mkdir(appImageExtractPath)
|
|
|
|
logger.debug(`appImageExtractPath dir ${appImageExtractPath} was created`)
|
2022-11-15 15:07:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return workingDir
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:54:08 +00:00
|
|
|
/**
|
2022-11-15 15:07:12 +00:00
|
|
|
* This function prepares:
|
|
|
|
* - the Prosody working dir
|
|
|
|
* - the binaries for the embeded Prosody (if needed).
|
2022-11-14 15:54:08 +00:00
|
|
|
* @param options
|
|
|
|
*/
|
|
|
|
async function prepareProsody (options: RegisterServerOptions): Promise<void> {
|
|
|
|
const logger = options.peertubeHelpers.logger
|
|
|
|
const filePaths = await getProsodyFilePaths(options)
|
2022-11-15 15:07:12 +00:00
|
|
|
|
|
|
|
logger.debug('Ensuring that the working dir exists')
|
2023-04-13 16:22:03 +00:00
|
|
|
await _ensureWorkingDir(
|
|
|
|
options,
|
|
|
|
filePaths.dir,
|
|
|
|
filePaths.data,
|
|
|
|
filePaths.certs,
|
|
|
|
filePaths.certsDirIsCustom,
|
|
|
|
filePaths.appImageExtractPath
|
|
|
|
)
|
2022-11-15 15:07:12 +00:00
|
|
|
|
2023-04-14 09:25:29 +00:00
|
|
|
try {
|
|
|
|
await fixRoomSubject(options, filePaths)
|
|
|
|
} catch (err) {
|
|
|
|
logger.error(err)
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:54:08 +00:00
|
|
|
const appImageToExtract = filePaths.appImageToExtract
|
|
|
|
if (!appImageToExtract) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const spawned = child_process.spawn(appImageToExtract, ['--appimage-extract'], {
|
2022-11-15 15:30:24 +00:00
|
|
|
cwd: filePaths.appImageExtractPath,
|
2022-11-14 15:54:08 +00:00
|
|
|
env: {
|
|
|
|
...process.env
|
|
|
|
}
|
|
|
|
})
|
|
|
|
spawned.stdout.on('data', (data) => {
|
|
|
|
logger.debug(`AppImage extract printed: ${data as string}`)
|
|
|
|
})
|
|
|
|
spawned.stderr.on('data', (data) => {
|
|
|
|
logger.error(`AppImage extract has errors: ${data as string}`)
|
|
|
|
})
|
|
|
|
spawned.on('error', reject)
|
|
|
|
spawned.on('close', (_code) => { // 'close' and not 'exit', to be sure it is finished.
|
2023-05-19 10:52:52 +00:00
|
|
|
disableLuaUnboundIfNeeded(options, filePaths.appImageExtractPath)
|
2022-11-14 15:54:08 +00:00
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:15:43 +00:00
|
|
|
interface ProsodyCtlResult {
|
|
|
|
code: number | null
|
|
|
|
stdout: string
|
|
|
|
sterr: string
|
|
|
|
message: string
|
2021-04-13 16:00:45 +00:00
|
|
|
}
|
2023-04-13 10:41:54 +00:00
|
|
|
interface ProsodyCtlOptions {
|
|
|
|
additionalArgs?: string[]
|
|
|
|
yesMode?: boolean
|
|
|
|
stdErrFilter?: (data: string) => boolean
|
|
|
|
}
|
|
|
|
async function prosodyCtl (
|
|
|
|
options: RegisterServerOptions, command: string, prosodyCtlOptions?: ProsodyCtlOptions
|
|
|
|
): Promise<ProsodyCtlResult> {
|
2021-04-14 15:10:22 +00:00
|
|
|
const logger = options.peertubeHelpers.logger
|
|
|
|
logger.debug('Calling prosodyCtl with command ' + command)
|
|
|
|
|
2021-04-14 14:14:56 +00:00
|
|
|
const filePaths = await getProsodyFilePaths(options)
|
|
|
|
if (!/^\w+$/.test(command)) {
|
|
|
|
throw new Error(`Invalid prosodyctl command '${command}'`)
|
|
|
|
}
|
2021-04-18 15:48:21 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-12-12 18:17:43 +00:00
|
|
|
if (!filePaths.execCtl) {
|
|
|
|
reject(new Error('Missing prosodyctl command executable'))
|
|
|
|
return
|
|
|
|
}
|
2021-04-14 14:14:56 +00:00
|
|
|
let d: string = ''
|
|
|
|
let e: string = ''
|
2021-04-14 16:15:43 +00:00
|
|
|
let m: string = ''
|
2022-11-14 15:54:08 +00:00
|
|
|
const cmdArgs = [
|
|
|
|
...filePaths.execCtlArgs,
|
2021-04-14 14:14:56 +00:00
|
|
|
'--config',
|
|
|
|
filePaths.config,
|
|
|
|
command
|
2022-11-14 15:54:08 +00:00
|
|
|
]
|
2023-04-13 10:41:54 +00:00
|
|
|
prosodyCtlOptions?.additionalArgs?.forEach(arg => {
|
|
|
|
// No need to check for code injection, child_process.spawn will escape args correctly.
|
|
|
|
cmdArgs.push(arg)
|
|
|
|
})
|
2022-11-14 15:54:08 +00:00
|
|
|
const spawned = child_process.spawn(filePaths.execCtl, cmdArgs, {
|
2021-04-14 14:14:56 +00:00
|
|
|
cwd: filePaths.dir,
|
|
|
|
env: {
|
|
|
|
...process.env,
|
|
|
|
PROSODY_CONFIG: filePaths.config
|
|
|
|
}
|
|
|
|
})
|
2023-04-13 10:41:54 +00:00
|
|
|
|
|
|
|
let yesModeInterval: NodeJS.Timer
|
|
|
|
if (prosodyCtlOptions?.yesMode) {
|
|
|
|
yesModeInterval = setInterval(() => {
|
|
|
|
options.peertubeHelpers.logger.debug('ProsodyCtl was called in yesMode, writing to standard input.')
|
|
|
|
spawned.stdin.write('\n')
|
|
|
|
}, 10)
|
2024-06-11 20:45:00 +00:00
|
|
|
spawned.stdin.on('close', () => {
|
|
|
|
options.peertubeHelpers.logger.debug('ProsodyCtl standard input closed, clearing interval.')
|
|
|
|
clearInterval(yesModeInterval)
|
|
|
|
})
|
|
|
|
spawned.stdin.on('error', () => {
|
|
|
|
options.peertubeHelpers.logger.debug('ProsodyCtl standard input errored, clearing interval.')
|
|
|
|
clearInterval(yesModeInterval)
|
|
|
|
})
|
2023-04-13 10:41:54 +00:00
|
|
|
}
|
|
|
|
|
2021-04-14 14:14:56 +00:00
|
|
|
spawned.stdout.on('data', (data) => {
|
|
|
|
d += data as string
|
2021-04-14 16:15:43 +00:00
|
|
|
m += data as string
|
2021-04-14 14:14:56 +00:00
|
|
|
})
|
|
|
|
spawned.stderr.on('data', (data) => {
|
2023-04-13 10:41:54 +00:00
|
|
|
if (prosodyCtlOptions?.stdErrFilter) {
|
|
|
|
if (!prosodyCtlOptions.stdErrFilter('' + (data as string))) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-04-14 14:14:56 +00:00
|
|
|
options.peertubeHelpers.logger.error(`Spawned command ${command} has errors: ${data as string}`)
|
|
|
|
e += data as string
|
2021-04-14 16:15:43 +00:00
|
|
|
m += data as string
|
2021-04-14 14:14:56 +00:00
|
|
|
})
|
2021-04-18 15:48:21 +00:00
|
|
|
spawned.on('error', reject)
|
2022-11-14 15:54:08 +00:00
|
|
|
|
|
|
|
// on 'close' and not 'exit', to be sure everything is done
|
|
|
|
// (else it can cause trouble by cleaning AppImage extract too soon)
|
|
|
|
spawned.on('close', (code) => {
|
2021-04-14 16:15:43 +00:00
|
|
|
resolve({
|
|
|
|
code: code,
|
|
|
|
stdout: d,
|
|
|
|
sterr: e,
|
|
|
|
message: m
|
|
|
|
})
|
2021-04-14 14:14:56 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getProsodyAbout (options: RegisterServerOptions): Promise<string> {
|
2021-04-14 16:15:43 +00:00
|
|
|
const ctl = await prosodyCtl(options, 'about')
|
|
|
|
return ctl.message
|
2021-04-14 14:14:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 12:59:52 +00:00
|
|
|
async function reloadProsody (options: RegisterServerOptions): Promise<boolean> {
|
|
|
|
const reload = await prosodyCtl(options, 'reload')
|
|
|
|
if (reload.code) {
|
|
|
|
options.peertubeHelpers.logger.error('reloadProsody failed: ' + JSON.stringify(reload))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-04-07 12:34:10 +00:00
|
|
|
async function checkProsody (options: RegisterServerOptions): Promise<string> {
|
|
|
|
const ctl = await prosodyCtl(options, 'check')
|
|
|
|
return ctl.message
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:15:43 +00:00
|
|
|
interface ProsodyRunning {
|
|
|
|
ok: boolean
|
|
|
|
messages: string[]
|
|
|
|
}
|
2021-04-14 13:26:00 +00:00
|
|
|
async function testProsodyRunning (options: RegisterServerOptions): Promise<ProsodyRunning> {
|
2021-04-13 15:13:41 +00:00
|
|
|
const { peertubeHelpers } = options
|
2021-04-14 15:10:22 +00:00
|
|
|
const logger = peertubeHelpers.logger
|
|
|
|
logger.info('Checking if Prosody is running')
|
|
|
|
|
2021-04-14 13:26:00 +00:00
|
|
|
const result: ProsodyRunning = {
|
2021-04-13 16:00:45 +00:00
|
|
|
ok: false,
|
|
|
|
messages: []
|
|
|
|
}
|
|
|
|
|
2021-04-14 13:26:00 +00:00
|
|
|
const filePaths = await getProsodyFilePaths(options)
|
|
|
|
try {
|
2021-04-14 15:10:22 +00:00
|
|
|
logger.debug('Trying to access the pid file')
|
2021-04-14 13:26:00 +00:00
|
|
|
await fs.promises.access(filePaths.pid, fs.constants.R_OK)
|
2021-04-14 14:14:56 +00:00
|
|
|
result.messages.push(`Pid file ${filePaths.pid} found`)
|
2021-04-14 13:26:00 +00:00
|
|
|
} catch (error) {
|
2021-04-14 15:10:22 +00:00
|
|
|
logger.debug(`Failed to access pid file: ${error as string}`)
|
2021-04-14 13:26:00 +00:00
|
|
|
result.messages.push(`Pid file ${filePaths.pid} not found`)
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:15:43 +00:00
|
|
|
const status = await prosodyCtl(options, 'status')
|
|
|
|
result.messages.push('Prosodyctl status: ' + status.message)
|
|
|
|
if (status.code) {
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-04-14 13:26:00 +00:00
|
|
|
result.ok = true
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
async function testProsodyCorrectlyRunning (options: RegisterServerOptions): Promise<ProsodyRunning> {
|
|
|
|
const { peertubeHelpers } = options
|
|
|
|
peertubeHelpers.logger.info('Checking if Prosody is correctly running')
|
|
|
|
const result = await testProsodyRunning(options)
|
|
|
|
if (!result.ok) { return result }
|
|
|
|
result.ok = false // more tests to come
|
2021-04-13 15:13:41 +00:00
|
|
|
|
2021-04-14 16:15:43 +00:00
|
|
|
try {
|
2021-04-15 10:17:08 +00:00
|
|
|
const wantedConfig = await getProsodyConfig(options)
|
2021-12-11 16:12:04 +00:00
|
|
|
const filePath = wantedConfig.paths.config
|
2021-04-14 16:15:43 +00:00
|
|
|
|
2021-12-11 16:12:04 +00:00
|
|
|
await fs.promises.access(filePath, fs.constants.R_OK) // throw an error if file does not exist.
|
|
|
|
result.messages.push(`The prosody configuration file (${filePath}) exists`)
|
|
|
|
const actualContent = await fs.promises.readFile(filePath, {
|
|
|
|
encoding: 'utf-8'
|
|
|
|
})
|
|
|
|
|
|
|
|
const wantedContent = wantedConfig.content
|
|
|
|
if (actualContent === wantedContent) {
|
|
|
|
result.messages.push('Prosody configuration file content is correct.')
|
|
|
|
} else {
|
|
|
|
result.messages.push('Prosody configuration file content is not correct.')
|
|
|
|
return result
|
2021-04-14 16:15:43 +00:00
|
|
|
}
|
2023-05-31 10:11:02 +00:00
|
|
|
|
|
|
|
if (!await missingSelfSignedCertificates(options, wantedConfig)) {
|
|
|
|
result.messages.push('No missing self signed certificates.')
|
|
|
|
} else {
|
|
|
|
result.messages.push('Missing self signed certificates.')
|
|
|
|
return result
|
|
|
|
}
|
2021-04-14 16:15:43 +00:00
|
|
|
} catch (error) {
|
|
|
|
result.messages.push('Error when requiring the prosody config file: ' + (error as string))
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
result.ok = true
|
2021-04-13 16:00:45 +00:00
|
|
|
return result
|
2021-04-13 15:13:41 +00:00
|
|
|
}
|
|
|
|
|
2023-05-19 10:52:52 +00:00
|
|
|
async function ensureProsodyRunning (
|
|
|
|
options: RegisterServerOptions,
|
|
|
|
forceRestart?: boolean,
|
|
|
|
restartProsodyInDebugMode?: boolean
|
|
|
|
): Promise<void> {
|
2022-10-10 16:08:20 +00:00
|
|
|
const { peertubeHelpers } = options
|
2021-04-13 15:13:41 +00:00
|
|
|
const logger = peertubeHelpers.logger
|
2021-04-14 15:10:22 +00:00
|
|
|
logger.debug('Calling ensureProsodyRunning')
|
2021-04-13 15:13:41 +00:00
|
|
|
|
2023-05-19 10:52:52 +00:00
|
|
|
if (forceRestart) {
|
|
|
|
logger.info('We want to force Prosody restart, skip checking the current state')
|
|
|
|
} else {
|
|
|
|
const r = await testProsodyCorrectlyRunning(options)
|
|
|
|
if (r.ok) {
|
|
|
|
r.messages.forEach(m => logger.debug(m))
|
|
|
|
logger.info('Prosody is already running correctly')
|
|
|
|
// Stop here. Nothing to change.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
logger.info('Prosody is not running correctly: ')
|
|
|
|
r.messages.forEach(m => logger.info(m))
|
2021-04-13 15:13:41 +00:00
|
|
|
}
|
2021-04-14 13:26:00 +00:00
|
|
|
|
2021-04-13 15:13:41 +00:00
|
|
|
// Shutting down...
|
2021-04-14 15:10:22 +00:00
|
|
|
logger.debug('Shutting down prosody')
|
2021-04-13 15:13:41 +00:00
|
|
|
await ensureProsodyNotRunning(options)
|
|
|
|
|
|
|
|
// writing the configuration file
|
2021-04-14 15:10:22 +00:00
|
|
|
logger.debug('Writing the configuration file')
|
2021-04-15 10:17:08 +00:00
|
|
|
const config = await writeProsodyConfig(options)
|
2021-04-13 15:13:41 +00:00
|
|
|
|
2021-04-15 10:17:08 +00:00
|
|
|
const filePaths = config.paths
|
2021-04-14 13:26:00 +00:00
|
|
|
|
2022-12-12 18:17:43 +00:00
|
|
|
if (!filePaths.exec) {
|
|
|
|
logger.info('No Prosody executable, cant run.')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-13 10:41:54 +00:00
|
|
|
// Check certicates if needed.
|
|
|
|
await ensureProsodyCertificates(options, config)
|
|
|
|
|
2021-04-14 13:26:00 +00:00
|
|
|
// launch prosody
|
2023-05-19 10:52:52 +00:00
|
|
|
let execArgs: string[] = filePaths.execArgs
|
|
|
|
if (restartProsodyInDebugMode) {
|
|
|
|
if (!filePaths.exec.includes('squashfs-root')) {
|
|
|
|
logger.error('Trying to enable the Prosody Debugger, but not using the AppImage. Cant work.')
|
|
|
|
} else {
|
|
|
|
const debuggerOptions = prosodyDebuggerOptions(options)
|
|
|
|
if (debuggerOptions) {
|
|
|
|
execArgs = [
|
|
|
|
'debug',
|
|
|
|
debuggerOptions.mobdebugPath,
|
|
|
|
debuggerOptions.mobdebugHost,
|
|
|
|
debuggerOptions.mobdebugPort,
|
|
|
|
...execArgs
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.info(
|
|
|
|
'Going to launch prosody (' +
|
|
|
|
filePaths.exec +
|
|
|
|
(execArgs.length ? ' ' + execArgs.join(' ') : '') +
|
|
|
|
')'
|
|
|
|
)
|
|
|
|
const prosody = child_process.spawn(filePaths.exec, execArgs, {
|
2021-04-14 13:26:00 +00:00
|
|
|
cwd: filePaths.dir,
|
|
|
|
env: {
|
|
|
|
...process.env,
|
|
|
|
PROSODY_CONFIG: filePaths.config
|
|
|
|
}
|
|
|
|
})
|
2021-04-14 15:55:26 +00:00
|
|
|
prosody.stdout?.on('data', (data) => {
|
|
|
|
logger.debug(`Prosody stdout: ${data as string}`)
|
|
|
|
})
|
|
|
|
prosody.stderr?.on('data', (data) => {
|
|
|
|
logger.error(`Prosody stderr: ${data as string}`)
|
|
|
|
})
|
2021-04-18 15:48:21 +00:00
|
|
|
prosody.on('error', (error) => {
|
|
|
|
logger.error(`Prosody exec error: ${JSON.stringify(error)}`)
|
|
|
|
})
|
2021-04-14 15:55:26 +00:00
|
|
|
prosody.on('close', (code) => {
|
|
|
|
logger.info(`Prosody process closed all stdio with code ${code ?? 'null'}`)
|
|
|
|
})
|
|
|
|
prosody.on('exit', (code) => {
|
|
|
|
logger.info(`Prosody process exited with code ${code ?? 'null'}`)
|
|
|
|
})
|
2021-04-14 15:48:46 +00:00
|
|
|
|
2021-04-15 10:17:08 +00:00
|
|
|
// Set the http-bind route.
|
2022-08-24 09:03:29 +00:00
|
|
|
await enableProxyRoute(options, {
|
2021-07-20 00:52:58 +00:00
|
|
|
host: config.host,
|
|
|
|
port: config.port
|
|
|
|
})
|
2021-04-15 10:17:08 +00:00
|
|
|
|
2021-04-14 15:48:46 +00:00
|
|
|
async function sleep (ms: number): Promise<any> {
|
|
|
|
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')
|
2021-04-14 16:15:43 +00:00
|
|
|
const status = await prosodyCtl(options, 'status')
|
|
|
|
if (!status.code) {
|
|
|
|
logger.info(`Prosody status: ${status.stdout}`)
|
2021-04-14 15:48:46 +00:00
|
|
|
processStarted = true
|
2021-04-14 16:15:43 +00:00
|
|
|
} else {
|
|
|
|
logger.warn(`Prosody status: ${status.message}`)
|
2021-04-14 15:48:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!processStarted) {
|
|
|
|
logger.error('It seems that the Prosody process is not up')
|
2021-05-12 12:59:52 +00:00
|
|
|
return
|
2021-04-14 15:48:46 +00:00
|
|
|
}
|
2021-05-12 12:59:52 +00:00
|
|
|
logger.info('Prosody is running')
|
2023-04-13 15:00:34 +00:00
|
|
|
await startProsodyLogRotate(options, filePaths)
|
|
|
|
await startProsodyCertificatesRenewCheck(options, config)
|
2021-04-13 15:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function ensureProsodyNotRunning (options: RegisterServerOptions): Promise<void> {
|
|
|
|
const { peertubeHelpers } = options
|
2021-04-14 15:10:22 +00:00
|
|
|
const logger = peertubeHelpers.logger
|
|
|
|
logger.info('Checking if Prosody is running, and shutting it down if so')
|
|
|
|
|
2021-05-12 12:59:52 +00:00
|
|
|
stopProsodyLogRotate(options)
|
2023-04-13 15:00:34 +00:00
|
|
|
stopProsodyCertificatesRenewCheck(options)
|
2021-05-12 12:59:52 +00:00
|
|
|
|
2021-04-14 15:10:22 +00:00
|
|
|
// NB: this function is called on plugin unregister, even if prosody is not used
|
|
|
|
// so we must avoid creating the working dir now
|
|
|
|
const filePaths = await getProsodyFilePaths(options)
|
|
|
|
if (!fs.existsSync(filePaths.dir)) {
|
|
|
|
logger.info(`The working dir ${filePaths.dir} does not exist, assuming there is no prosody on this server`)
|
|
|
|
return
|
|
|
|
}
|
2021-04-13 15:13:41 +00:00
|
|
|
|
2022-08-24 10:24:35 +00:00
|
|
|
logger.debug('Removing proxy route')
|
|
|
|
await disableProxyRoute(options)
|
|
|
|
|
2021-04-14 15:10:22 +00:00
|
|
|
logger.debug('Calling prosodyctl to stop the process')
|
2021-04-14 16:15:43 +00:00
|
|
|
const status = await prosodyCtl(options, 'stop')
|
|
|
|
logger.info(`ProsodyCtl command returned: ${status.message}`)
|
2021-04-13 15:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
2021-04-14 14:14:56 +00:00
|
|
|
getProsodyAbout,
|
2023-04-07 12:34:10 +00:00
|
|
|
checkProsody,
|
2021-04-14 13:26:00 +00:00
|
|
|
testProsodyRunning,
|
2021-04-13 15:13:41 +00:00
|
|
|
testProsodyCorrectlyRunning,
|
2022-11-14 15:54:08 +00:00
|
|
|
prepareProsody,
|
2021-04-13 15:13:41 +00:00
|
|
|
ensureProsodyRunning,
|
2023-04-13 15:00:34 +00:00
|
|
|
ensureProsodyNotRunning,
|
|
|
|
prosodyCtl,
|
|
|
|
reloadProsody
|
2021-04-13 15:13:41 +00:00
|
|
|
}
|