X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fextra-utils%2Fserver%2Fserver.ts;h=31224ebe9f70f1a0b2149da9f5206addca049f83;hb=5678353d4fb0ddd8bea044868576ee02cdbabedb;hp=cc6df2efe4dc1957c8b94dbd0563ba314eddd0c4;hpb=08642a765ea514a00f159db898edf14c376fbe6c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts index cc6df2efe..31224ebe9 100644 --- a/shared/extra-utils/server/server.ts +++ b/shared/extra-utils/server/server.ts @@ -2,8 +2,8 @@ import { ChildProcess, fork } from 'child_process' import { copy } from 'fs-extra' import { join } from 'path' import { root } from '@server/helpers/core-utils' -import { randomInt } from '../../core-utils/miscs/miscs' -import { VideoChannel } from '../../models/videos' +import { randomInt } from '@shared/core-utils' +import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '../../models/videos' import { BulkCommand } from '../bulk' import { CLICommand } from '../cli' import { CustomPagesCommand } from '../custom-pages' @@ -38,10 +38,13 @@ import { PluginsCommand } from './plugins-command' import { RedundancyCommand } from './redundancy-command' import { ServersCommand } from './servers-command' import { StatsCommand } from './stats-command' +import { ObjectStorageCommand } from './object-storage-command' export type RunServerOptions = { hideLogs?: boolean - execArgv?: string[] + nodeArgs?: string[] + peertubeArgs?: string[] + env?: { [ id: string ]: string } } export class PeerTubeServer { @@ -53,6 +56,7 @@ export class PeerTubeServer { port?: number rtmpPort?: number + rtmpsPort?: number parallel?: boolean internalServerNumber: number @@ -74,19 +78,9 @@ export class PeerTubeServer { channel?: VideoChannel - video?: { - id: number - uuid: string - shortUUID: string - name?: string - url?: string - - account?: { - name: string - } - - embedPath?: string - } + video?: Video + videoCreated?: VideoCreateResult + videoDetails?: VideoDetails videos?: { id: number, uuid: string }[] } @@ -130,6 +124,7 @@ export class PeerTubeServer { servers?: ServersCommand login?: LoginCommand users?: UsersCommand + objectStorage?: ObjectStorageCommand videos?: VideosCommand constructor (options: { serverNumber: number } | { url: string }) { @@ -160,6 +155,7 @@ export class PeerTubeServer { this.internalServerNumber = this.parallel ? this.randomServer() : this.serverNumber this.rtmpPort = this.parallel ? this.randomRTMP() : 1936 + this.rtmpsPort = this.parallel ? this.randomRTMP() : 1937 this.port = 9000 + this.internalServerNumber this.url = `http://localhost:${this.port}` @@ -176,13 +172,13 @@ export class PeerTubeServer { this.port = parseInt(parsed.port) } - async flushAndRun (configOverride?: Object, args = [], options: RunServerOptions = {}) { + async flushAndRun (configOverride?: Object, options: RunServerOptions = {}) { await ServersCommand.flushTests(this.internalServerNumber) - return this.run(configOverride, args, options) + return this.run(configOverride, options) } - async run (configOverrideArg?: any, args = [], options: RunServerOptions = {}) { + async run (configOverrideArg?: any, options: RunServerOptions = {}) { // These actions are async so we need to be sure that they have both been done const serverRunString = { 'HTTP server listening': false @@ -211,17 +207,34 @@ export class PeerTubeServer { env['NODE_APP_INSTANCE'] = this.internalServerNumber.toString() env['NODE_CONFIG'] = JSON.stringify(configOverride) + if (options.env) { + Object.assign(env, options.env) + } + const forkOptions = { silent: true, env, detached: true, - execArgv: options.execArgv || [] + execArgv: options.nodeArgs || [] } - return new Promise(res => { + return new Promise((res, rej) => { const self = this - this.app = fork(join(root(), 'dist', 'server.js'), args, forkOptions) + this.app = fork(join(root(), 'dist', 'server.js'), options.peertubeArgs || [], forkOptions) + + const onPeerTubeExit = () => rej(new Error('Process exited')) + const onParentExit = () => { + if (!this.app || !this.app.pid) return + + try { + process.kill(self.app.pid) + } catch { /* empty */ } + } + + this.app.on('exit', onPeerTubeExit) + process.on('exit', onParentExit) + this.app.stdout.on('data', function onStdout (data) { let dontContinue = false @@ -249,15 +262,11 @@ export class PeerTubeServer { if (options.hideLogs === false) { console.log(data.toString()) } else { + process.removeListener('exit', onParentExit) self.app.stdout.removeListener('data', onStdout) + self.app.removeListener('exit', onPeerTubeExit) } - process.on('exit', () => { - try { - process.kill(self.server.app.pid) - } catch { /* empty */ } - }) - res() }) }) @@ -313,6 +322,7 @@ export class PeerTubeServer { }, storage: { tmp: `test${this.internalServerNumber}/tmp/`, + bin: `test${this.internalServerNumber}/bin/`, avatars: `test${this.internalServerNumber}/avatars/`, videos: `test${this.internalServerNumber}/videos/`, streaming_playlists: `test${this.internalServerNumber}/streaming-playlists/`, @@ -374,5 +384,6 @@ export class PeerTubeServer { this.login = new LoginCommand(this) this.users = new UsersCommand(this) this.videos = new VideosCommand(this) + this.objectStorage = new ObjectStorageCommand(this) } }