2021-04-13 15:13:41 +00:00
|
|
|
import { writeProsodyConfig } from './config'
|
|
|
|
|
2021-04-13 16:00:45 +00:00
|
|
|
interface ProsodyCorrectlyRunning {
|
|
|
|
ok: boolean
|
|
|
|
messages: string[]
|
|
|
|
}
|
|
|
|
|
2021-04-13 15:13:41 +00:00
|
|
|
/**
|
|
|
|
* @param options
|
|
|
|
* @returns true if prosody is running with up to date parameters. A string array of messages otherwise.
|
|
|
|
*/
|
2021-04-13 16:00:45 +00:00
|
|
|
async function testProsodyCorrectlyRunning (options: RegisterServerOptions): Promise<ProsodyCorrectlyRunning> {
|
2021-04-13 15:13:41 +00:00
|
|
|
const { peertubeHelpers } = options
|
|
|
|
peertubeHelpers.logger.info('Checking if Prosody is correctly running')
|
2021-04-13 16:00:45 +00:00
|
|
|
const result: ProsodyCorrectlyRunning = {
|
|
|
|
ok: false,
|
|
|
|
messages: []
|
|
|
|
}
|
|
|
|
|
|
|
|
result.messages.push('Pid file not found')
|
2021-04-13 15:13:41 +00:00
|
|
|
|
|
|
|
// TODO
|
|
|
|
peertubeHelpers.logger.error('testProsodyCorrectlyRunning not implemented yet.')
|
2021-04-13 16:00:45 +00:00
|
|
|
return result
|
2021-04-13 15:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function ensureProsodyRunning (options: RegisterServerOptions): Promise<void> {
|
|
|
|
const { peertubeHelpers, settingsManager } = options
|
|
|
|
const logger = peertubeHelpers.logger
|
|
|
|
|
|
|
|
const setting = await settingsManager.getSetting('chat-use-prosody')
|
|
|
|
if (!setting) {
|
|
|
|
logger.info('Prosody is not activated, we wont launch it')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const r = await testProsodyCorrectlyRunning(options)
|
2021-04-13 16:00:45 +00:00
|
|
|
if (r.ok) {
|
2021-04-13 15:13:41 +00:00
|
|
|
logger.info('Prosody is already running correctly')
|
|
|
|
return
|
|
|
|
}
|
2021-04-13 16:00:45 +00:00
|
|
|
logger.info('Prosody is not running correctly: ' + r.messages.join(', '))
|
2021-04-13 15:13:41 +00:00
|
|
|
// Shutting down...
|
|
|
|
await ensureProsodyNotRunning(options)
|
|
|
|
|
|
|
|
// writing the configuration file
|
|
|
|
await writeProsodyConfig(options)
|
|
|
|
|
|
|
|
// TODO: launch prosody
|
|
|
|
logger.error('ensureProsodyRunning not implemented yet.')
|
|
|
|
|
|
|
|
// TODO: listen for kill signal and kill prosody?
|
|
|
|
}
|
|
|
|
|
|
|
|
async function ensureProsodyNotRunning (options: RegisterServerOptions): Promise<void> {
|
|
|
|
const { peertubeHelpers } = options
|
|
|
|
peertubeHelpers.logger.info('Checking if Prosody is running, and shutting it down if so')
|
|
|
|
|
|
|
|
// TODO: implement this.
|
|
|
|
peertubeHelpers.logger.error('ensureProsodyNotRunning not implemented yet.')
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
testProsodyCorrectlyRunning,
|
|
|
|
ensureProsodyRunning,
|
|
|
|
ensureProsodyNotRunning
|
|
|
|
}
|