Remove backward compatibility (always using permanent working dir).
This commit is contained in:
parent
56f1c5895e
commit
af20f3918f
@ -20,8 +20,6 @@ If you are not using prosody for anything else on your server, you can then disa
|
|||||||
sudo systemctl disable prosody && sudo systemctl stop prosody
|
sudo systemctl disable prosody && sudo systemctl stop prosody
|
||||||
```
|
```
|
||||||
|
|
||||||
**NB:** with Peertube prior to version 3.2.0, the plugin will create a directory in the `/tmp/` folder. Please ensure that the `peertube` user has write access to this directory.
|
|
||||||
|
|
||||||
And that's it!
|
And that's it!
|
||||||
|
|
||||||
The Prosody process launched by the plugin will listen on a specific port, and only on the localhost interface.
|
The Prosody process launched by the plugin will listen on a specific port, and only on the localhost interface.
|
||||||
|
@ -9,12 +9,7 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const workingDir = await getWorkingDir(options)
|
const workingDir = await getWorkingDir(options)
|
||||||
result.messages.push('The working dir is: ' + workingDir.dir)
|
result.messages.push('The working dir is: ' + workingDir)
|
||||||
if (workingDir.permanent) {
|
|
||||||
result.messages.push('The working dir is permanent')
|
|
||||||
} else {
|
|
||||||
result.messages.push('The working dir is a temporary directory')
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
result.messages.push('Error when requiring the working dir: ' + (error as string))
|
result.messages.push('Error when requiring the working dir: ' + (error as string))
|
||||||
return result
|
return result
|
||||||
|
@ -1,66 +1,27 @@
|
|||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import { pluginName, getBaseRouterRoute } from '../helpers'
|
import { getBaseRouterRoute } from '../helpers'
|
||||||
import { ProsodyFilePaths } from './config/paths'
|
import { ProsodyFilePaths } from './config/paths'
|
||||||
import { ProsodyConfigContent } from './config/content'
|
import { ProsodyConfigContent } from './config/content'
|
||||||
import { getProsodyDomain } from './config/domain'
|
import { getProsodyDomain } from './config/domain'
|
||||||
import { getAPIKey } from '../apikey'
|
import { getAPIKey } from '../apikey'
|
||||||
import type { ProsodyLogLevel } from './config/content'
|
import type { ProsodyLogLevel } from './config/content'
|
||||||
|
|
||||||
async function _getTemporaryWorkingDir ({ peertubeHelpers, storageManager }: RegisterServerOptions): Promise<string> {
|
async function getWorkingDir (options: RegisterServerOptions): Promise<string> {
|
||||||
const tmpBaseDir = '/tmp/'
|
|
||||||
let value: string = await storageManager.getData('tempDirId')
|
|
||||||
|
|
||||||
function getPath (value: string): string {
|
|
||||||
return path.resolve(tmpBaseDir, pluginName + '-' + value)
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!value) {
|
|
||||||
peertubeHelpers.logger.info('Generating an id for temp dir')
|
|
||||||
value = Math.random().toString(36).slice(2, 12)
|
|
||||||
const name = getPath(value)
|
|
||||||
if (fs.existsSync(name)) {
|
|
||||||
peertubeHelpers.logger.info('The folder ' + name + ' already exists, generating another name...')
|
|
||||||
value = ''
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
await storageManager.storeData('tempDirId', value)
|
|
||||||
}
|
|
||||||
|
|
||||||
const dir = getPath(value)
|
|
||||||
return dir
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getWorkingDir (options: RegisterServerOptions): Promise<{
|
|
||||||
dir: string
|
|
||||||
permanent: boolean
|
|
||||||
}> {
|
|
||||||
const peertubeHelpers = options.peertubeHelpers
|
const peertubeHelpers = options.peertubeHelpers
|
||||||
const logger = peertubeHelpers.logger
|
const logger = peertubeHelpers.logger
|
||||||
logger.debug('Calling getWorkingDir')
|
logger.debug('Calling getWorkingDir')
|
||||||
|
|
||||||
if (peertubeHelpers.plugin?.getDataDirectoryPath) {
|
if (!peertubeHelpers.plugin?.getDataDirectoryPath) {
|
||||||
const dir = path.resolve(peertubeHelpers.plugin.getDataDirectoryPath(), 'prosody')
|
throw new Error('Cant get the plugin Data Directory')
|
||||||
logger.debug('getWorkingDir will return the permanent dir ' + dir)
|
|
||||||
return {
|
|
||||||
dir: dir,
|
|
||||||
permanent: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const dir = await _getTemporaryWorkingDir(options)
|
|
||||||
logger.debug('getWorkingDir will return the temporary dir ' + dir)
|
|
||||||
return {
|
|
||||||
dir: dir,
|
|
||||||
permanent: false
|
|
||||||
}
|
}
|
||||||
|
const dir = path.resolve(peertubeHelpers.plugin.getDataDirectoryPath(), 'prosody')
|
||||||
|
logger.debug('getWorkingDir will return the dir ' + dir)
|
||||||
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the working dir if needed, and returns it.
|
* Creates the working dir if needed, and returns it.
|
||||||
* NB: for now, I try to create a directory in /tmp/.
|
|
||||||
* To ensure that there is no conflict with another peertube instance,
|
|
||||||
* I used a randomly generated id that will be stored in database.
|
|
||||||
*/
|
*/
|
||||||
async function ensureWorkingDir (options: RegisterServerOptions): Promise<string> {
|
async function ensureWorkingDir (options: RegisterServerOptions): Promise<string> {
|
||||||
const logger = options.peertubeHelpers.logger
|
const logger = options.peertubeHelpers.logger
|
||||||
@ -90,11 +51,9 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
|
|||||||
const logger = options.peertubeHelpers.logger
|
const logger = options.peertubeHelpers.logger
|
||||||
logger.debug('Calling getProsodyFilePaths')
|
logger.debug('Calling getProsodyFilePaths')
|
||||||
|
|
||||||
const workingDir = await getWorkingDir(options)
|
const dir = await getWorkingDir(options)
|
||||||
const dir = workingDir.dir
|
|
||||||
return {
|
return {
|
||||||
dir: dir,
|
dir: dir,
|
||||||
permanent: workingDir.permanent,
|
|
||||||
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'),
|
||||||
@ -131,12 +90,12 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
|
|||||||
config.useHttpAuthentication(authApiUrl)
|
config.useHttpAuthentication(authApiUrl)
|
||||||
config.usePeertubeBosh(prosodyDomain, port)
|
config.usePeertubeBosh(prosodyDomain, port)
|
||||||
config.useMucHttpDefault(roomApiUrl)
|
config.useMucHttpDefault(roomApiUrl)
|
||||||
if (paths.permanent) {
|
|
||||||
// TODO: add a settings so that admin can choose? (on/off and duration)
|
// TODO: add a settings so that admin can choose? (on/off and duration)
|
||||||
config.useMam('1w') // Remove archived messages after 1 week
|
config.useMam('1w') // Remove archived messages after 1 week
|
||||||
// TODO: add a settings to choose?
|
// TODO: add a settings to choose?
|
||||||
config.useDefaultPersistent()
|
config.useDefaultPersistent()
|
||||||
}
|
|
||||||
let logLevel: ProsodyLogLevel | undefined
|
let logLevel: ProsodyLogLevel | undefined
|
||||||
if (logger.level && (typeof logger.level === 'string')) {
|
if (logger.level && (typeof logger.level === 'string')) {
|
||||||
if (logger.level === 'error' || logger.level === 'info' || logger.level === 'debug') {
|
if (logger.level === 'error' || logger.level === 'info' || logger.level === 'debug') {
|
||||||
|
@ -212,7 +212,6 @@ class ProsodyConfigContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Calling this method makes Prosody use mod_muc_mam to store rooms history.
|
* Calling this method makes Prosody use mod_muc_mam to store rooms history.
|
||||||
* Should not be used when using a temporary dir.
|
|
||||||
* @param duration: how long the server must store messages. See https://prosody.im/doc/modules/mod_muc_mam
|
* @param duration: how long the server must store messages. See https://prosody.im/doc/modules/mod_muc_mam
|
||||||
*/
|
*/
|
||||||
useMam (duration: string): void {
|
useMam (duration: string): void {
|
||||||
@ -232,7 +231,6 @@ class ProsodyConfigContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Rooms will be persistent by default (they will not be deleted if no participant).
|
* Rooms will be persistent by default (they will not be deleted if no participant).
|
||||||
* Should not be used when using a temporary dir.
|
|
||||||
*/
|
*/
|
||||||
useDefaultPersistent (): void {
|
useDefaultPersistent (): void {
|
||||||
this.muc.set('muc_room_default_persistent', true)
|
this.muc.set('muc_room_default_persistent', true)
|
||||||
|
@ -6,7 +6,6 @@ interface ProsodyFilePaths {
|
|||||||
config: string
|
config: string
|
||||||
data: string
|
data: string
|
||||||
modules: string
|
modules: string
|
||||||
permanent: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user