WIP. Spawning prosody.
This commit is contained in:
parent
3f6d81ee7e
commit
f5b438d587
@ -40,6 +40,7 @@ async function getWorkingDir ({ peertubeHelpers, storageManager }: RegisterServe
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ProsodyFilePaths {
|
interface ProsodyFilePaths {
|
||||||
|
dir: string
|
||||||
pid: string
|
pid: string
|
||||||
error: string
|
error: string
|
||||||
log: string
|
log: string
|
||||||
@ -48,6 +49,7 @@ interface ProsodyFilePaths {
|
|||||||
async function getProsodyFilePaths (options: RegisterServerOptions): Promise<ProsodyFilePaths> {
|
async function getProsodyFilePaths (options: RegisterServerOptions): Promise<ProsodyFilePaths> {
|
||||||
const dir = await getWorkingDir(options)
|
const dir = await getWorkingDir(options)
|
||||||
return {
|
return {
|
||||||
|
dir: dir,
|
||||||
pid: path.resolve(dir, 'prosody.pid'),
|
pid: path.resolve(dir, 'prosody.pid'),
|
||||||
error: path.resolve(dir, 'prosody.err'),
|
error: path.resolve(dir, 'prosody.err'),
|
||||||
log: path.resolve(dir, 'prosody.log'),
|
log: path.resolve(dir, 'prosody.log'),
|
||||||
@ -82,7 +84,7 @@ modules_disabled = {
|
|||||||
|
|
||||||
allow_registration = false
|
allow_registration = false
|
||||||
|
|
||||||
daemonize = true;
|
daemonize = false;
|
||||||
|
|
||||||
pidfile = "${paths.pid}";
|
pidfile = "${paths.pid}";
|
||||||
|
|
||||||
|
@ -1,23 +1,40 @@
|
|||||||
import { writeProsodyConfig } from './config'
|
import { getProsodyFilePaths, writeProsodyConfig } from './config'
|
||||||
|
import * as fs from 'fs'
|
||||||
|
import * as util from 'util'
|
||||||
|
|
||||||
interface ProsodyCorrectlyRunning {
|
const exec = util.promisify(require('child_process').exec)
|
||||||
|
|
||||||
|
interface ProsodyRunning {
|
||||||
ok: boolean
|
ok: boolean
|
||||||
messages: string[]
|
messages: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
async function testProsodyRunning (options: RegisterServerOptions): Promise<ProsodyRunning> {
|
||||||
* @param options
|
|
||||||
* @returns true if prosody is running with up to date parameters. A string array of messages otherwise.
|
|
||||||
*/
|
|
||||||
async function testProsodyCorrectlyRunning (options: RegisterServerOptions): Promise<ProsodyCorrectlyRunning> {
|
|
||||||
const { peertubeHelpers } = options
|
const { peertubeHelpers } = options
|
||||||
peertubeHelpers.logger.info('Checking if Prosody is correctly running')
|
peertubeHelpers.logger.info('Checking if Prosody is running')
|
||||||
const result: ProsodyCorrectlyRunning = {
|
const result: ProsodyRunning = {
|
||||||
ok: false,
|
ok: false,
|
||||||
messages: []
|
messages: []
|
||||||
}
|
}
|
||||||
|
|
||||||
result.messages.push('Pid file not found')
|
const filePaths = await getProsodyFilePaths(options)
|
||||||
|
try {
|
||||||
|
await fs.promises.access(filePaths.pid, fs.constants.R_OK)
|
||||||
|
} catch (error) {
|
||||||
|
result.messages.push(`Pid file ${filePaths.pid} not found`)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
peertubeHelpers.logger.error('testProsodyCorrectlyRunning not implemented yet.')
|
peertubeHelpers.logger.error('testProsodyCorrectlyRunning not implemented yet.')
|
||||||
@ -36,18 +53,30 @@ async function ensureProsodyRunning (options: RegisterServerOptions): Promise<vo
|
|||||||
|
|
||||||
const r = await testProsodyCorrectlyRunning(options)
|
const r = await testProsodyCorrectlyRunning(options)
|
||||||
if (r.ok) {
|
if (r.ok) {
|
||||||
|
r.messages.forEach(m => logger.debug(m))
|
||||||
logger.info('Prosody is already running correctly')
|
logger.info('Prosody is already running correctly')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.info('Prosody is not running correctly: ' + r.messages.join(', '))
|
logger.info('Prosody is not running correctly: ')
|
||||||
|
r.messages.forEach(m => logger.info(m))
|
||||||
|
|
||||||
// Shutting down...
|
// Shutting down...
|
||||||
await ensureProsodyNotRunning(options)
|
await ensureProsodyNotRunning(options)
|
||||||
|
|
||||||
// writing the configuration file
|
// writing the configuration file
|
||||||
await writeProsodyConfig(options)
|
await writeProsodyConfig(options)
|
||||||
|
|
||||||
// TODO: launch prosody
|
const filePaths = await getProsodyFilePaths(options)
|
||||||
logger.error('ensureProsodyRunning not implemented yet.')
|
|
||||||
|
// launch prosody
|
||||||
|
logger.info('Going to launch prosody...')
|
||||||
|
await exec('prosody', {
|
||||||
|
cwd: filePaths.dir,
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
PROSODY_CONFIG: filePaths.config
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// TODO: listen for kill signal and kill prosody?
|
// TODO: listen for kill signal and kill prosody?
|
||||||
}
|
}
|
||||||
@ -61,6 +90,7 @@ async function ensureProsodyNotRunning (options: RegisterServerOptions): Promise
|
|||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
testProsodyRunning,
|
||||||
testProsodyCorrectlyRunning,
|
testProsodyCorrectlyRunning,
|
||||||
ensureProsodyRunning,
|
ensureProsodyRunning,
|
||||||
ensureProsodyNotRunning
|
ensureProsodyNotRunning
|
||||||
|
Loading…
x
Reference in New Issue
Block a user