Prosody AppImage: extract in a dedicated folder

This commit is contained in:
John Livingston 2022-11-15 16:30:24 +01:00
parent 27e8fbf05f
commit 8f5b2ae565
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
3 changed files with 21 additions and 7 deletions

View File

@ -33,6 +33,10 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
let execCtl let execCtl
let execCtlArgs: string[] let execCtlArgs: string[]
let appImageToExtract let appImageToExtract
// this one is always needed (must create the directory on startup)
const appImageExtractPath = path.resolve(dir, '..', 'prosodyAppImage')
if (settings['use-system-prosody']) { if (settings['use-system-prosody']) {
exec = 'prosody' exec = 'prosody'
execArgs = [] execArgs = []
@ -40,11 +44,12 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
execCtlArgs = [] execCtlArgs = []
} else { } else {
appImageToExtract = path.resolve(__dirname, '../../prosody/livechat-prosody-x86_64.AppImage') appImageToExtract = path.resolve(__dirname, '../../prosody/livechat-prosody-x86_64.AppImage')
exec = path.resolve(dir, 'squashfs-root/AppRun') // the AppImage will be extracted in the working dir exec = path.resolve(appImageExtractPath, 'squashfs-root/AppRun')
execArgs = ['prosody'] execArgs = ['prosody']
execCtl = exec execCtl = exec
execCtlArgs = ['prosodyctl'] execCtlArgs = ['prosodyctl']
} }
return { return {
dir: dir, dir: dir,
pid: path.resolve(dir, 'prosody.pid'), pid: path.resolve(dir, 'prosody.pid'),
@ -58,7 +63,8 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
execArgs, execArgs,
execCtl, execCtl,
execCtlArgs, execCtlArgs,
appImageToExtract appImageToExtract,
appImageExtractPath
} }
} }

View File

@ -12,6 +12,7 @@ interface ProsodyFilePaths {
execCtl: string execCtl: string
execCtlArgs: string[] execCtlArgs: string[]
appImageToExtract?: string appImageToExtract?: string
appImageExtractPath: string
} }
export { export {

View File

@ -8,10 +8,11 @@ import * as child_process from 'child_process'
async function _ensureWorkingDir ( async function _ensureWorkingDir (
options: RegisterServerOptions, options: RegisterServerOptions,
workingDir: string, workingDir: string,
dataDir: string dataDir: string,
appImageExtractPath: string
): Promise<string> { ): Promise<string> {
const logger = options.peertubeHelpers.logger const logger = options.peertubeHelpers.logger
logger.debug('Calling ensureworkingDir') logger.debug('Calling _ensureworkingDir')
if (!fs.existsSync(workingDir)) { if (!fs.existsSync(workingDir)) {
logger.info(`The working dir ${workingDir} does not exists, trying to create it`) logger.info(`The working dir ${workingDir} does not exists, trying to create it`)
@ -25,7 +26,13 @@ async function _ensureWorkingDir (
if (!fs.existsSync(dataDir)) { if (!fs.existsSync(dataDir)) {
logger.info(`The data dir ${dataDir} does not exists, trying to create it`) logger.info(`The data dir ${dataDir} does not exists, trying to create it`)
await fs.promises.mkdir(dataDir) await fs.promises.mkdir(dataDir)
logger.debug(`Working dir ${dataDir} was created`) logger.debug(`data dir ${dataDir} was created`)
}
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`)
} }
return workingDir return workingDir
@ -42,7 +49,7 @@ async function prepareProsody (options: RegisterServerOptions): Promise<void> {
const filePaths = await getProsodyFilePaths(options) const filePaths = await getProsodyFilePaths(options)
logger.debug('Ensuring that the working dir exists') logger.debug('Ensuring that the working dir exists')
await _ensureWorkingDir(options, filePaths.dir, filePaths.data) await _ensureWorkingDir(options, filePaths.dir, filePaths.data, filePaths.appImageExtractPath)
const appImageToExtract = filePaths.appImageToExtract const appImageToExtract = filePaths.appImageToExtract
if (!appImageToExtract) { if (!appImageToExtract) {
@ -51,7 +58,7 @@ async function prepareProsody (options: RegisterServerOptions): Promise<void> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const spawned = child_process.spawn(appImageToExtract, ['--appimage-extract'], { const spawned = child_process.spawn(appImageToExtract, ['--appimage-extract'], {
cwd: filePaths.dir, cwd: filePaths.appImageExtractPath,
env: { env: {
...process.env ...process.env
} }