aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server/server.ts
diff options
context:
space:
mode:
authorJelle Besseling <jelle@pingiun.com>2021-08-17 08:26:20 +0200
committerGitHub <noreply@github.com>2021-08-17 08:26:20 +0200
commit0305db28c98fd6cf43a3c50ba92c76215e99d512 (patch)
tree33b753a19728d9f453c1aa4f19b36ac797e5fe80 /shared/extra-utils/server/server.ts
parentf88ae8f5bc223579313b28582de9101944a4a814 (diff)
downloadPeerTube-0305db28c98fd6cf43a3c50ba92c76215e99d512.tar.gz
PeerTube-0305db28c98fd6cf43a3c50ba92c76215e99d512.tar.zst
PeerTube-0305db28c98fd6cf43a3c50ba92c76215e99d512.zip
Add support for saving video files to object storage (#4290)
* Add support for saving video files to object storage * Add support for custom url generation on s3 stored files Uses two config keys to support url generation that doesn't directly go to (compatible s3). Can be used to generate urls to any cache server or CDN. * Upload files to s3 concurrently and delete originals afterwards * Only publish after move to object storage is complete * Use base url instead of url template * Fix mistyped config field * Add rudenmentary way to download before transcode * Implement Chocobozzz suggestions https://github.com/Chocobozzz/PeerTube/pull/4290#issuecomment-891670478 The remarks in question: Try to use objectStorage prefix instead of s3 prefix for your function/variables/config names Prefer to use a tree for the config: s3.streaming_playlists_bucket -> object_storage.streaming_playlists.bucket Use uppercase for config: S3.STREAMING_PLAYLISTS_BUCKETINFO.bucket -> OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET (maybe BUCKET_NAME instead of BUCKET) I suggest to rename moveJobsRunning to pendingMovingJobs (or better, create a dedicated videoJobInfo table with a pendingMove & videoId columns so we could also use this table to track pending transcoding jobs) https://github.com/Chocobozzz/PeerTube/pull/4290/files#diff-3e26d41ca4bda1de8e1747af70ca2af642abcc1e9e0bfb94239ff2165acfbde5R19 uses a string instead of an integer I think we should store the origin object storage URL in fileUrl, without base_url injection. Instead, inject the base_url at "runtime" so admins can easily change this configuration without running a script to update DB URLs * Import correct function * Support multipart upload * Remove import of node 15.0 module stream/promises * Extend maximum upload job length Using the same value as for redundancy downloading seems logical * Use dynamic part size for really large uploads Also adds very small part size for local testing * Fix decreasePendingMove query * Resolve various PR comments * Move to object storage after optimize * Make upload size configurable and increase default * Prune webtorrent files that are stored in object storage * Move files after transcoding jobs * Fix federation * Add video path manager * Support move to external storage job in client * Fix live object storage tests Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'shared/extra-utils/server/server.ts')
-rw-r--r--shared/extra-utils/server/server.ts18
1 files changed, 17 insertions, 1 deletions
diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts
index 3c335b8e4..bc5e1cd5f 100644
--- a/shared/extra-utils/server/server.ts
+++ b/shared/extra-utils/server/server.ts
@@ -38,11 +38,13 @@ import { PluginsCommand } from './plugins-command'
38import { RedundancyCommand } from './redundancy-command' 38import { RedundancyCommand } from './redundancy-command'
39import { ServersCommand } from './servers-command' 39import { ServersCommand } from './servers-command'
40import { StatsCommand } from './stats-command' 40import { StatsCommand } from './stats-command'
41import { ObjectStorageCommand } from './object-storage-command'
41 42
42export type RunServerOptions = { 43export type RunServerOptions = {
43 hideLogs?: boolean 44 hideLogs?: boolean
44 nodeArgs?: string[] 45 nodeArgs?: string[]
45 peertubeArgs?: string[] 46 peertubeArgs?: string[]
47 env?: { [ id: string ]: string }
46} 48}
47 49
48export class PeerTubeServer { 50export class PeerTubeServer {
@@ -121,6 +123,7 @@ export class PeerTubeServer {
121 servers?: ServersCommand 123 servers?: ServersCommand
122 login?: LoginCommand 124 login?: LoginCommand
123 users?: UsersCommand 125 users?: UsersCommand
126 objectStorage?: ObjectStorageCommand
124 videos?: VideosCommand 127 videos?: VideosCommand
125 128
126 constructor (options: { serverNumber: number } | { url: string }) { 129 constructor (options: { serverNumber: number } | { url: string }) {
@@ -202,6 +205,10 @@ export class PeerTubeServer {
202 env['NODE_APP_INSTANCE'] = this.internalServerNumber.toString() 205 env['NODE_APP_INSTANCE'] = this.internalServerNumber.toString()
203 env['NODE_CONFIG'] = JSON.stringify(configOverride) 206 env['NODE_CONFIG'] = JSON.stringify(configOverride)
204 207
208 if (options.env) {
209 Object.assign(env, options.env)
210 }
211
205 const forkOptions = { 212 const forkOptions = {
206 silent: true, 213 silent: true,
207 env, 214 env,
@@ -209,10 +216,17 @@ export class PeerTubeServer {
209 execArgv: options.nodeArgs || [] 216 execArgv: options.nodeArgs || []
210 } 217 }
211 218
212 return new Promise<void>(res => { 219 return new Promise<void>((res, rej) => {
213 const self = this 220 const self = this
214 221
215 this.app = fork(join(root(), 'dist', 'server.js'), options.peertubeArgs || [], forkOptions) 222 this.app = fork(join(root(), 'dist', 'server.js'), options.peertubeArgs || [], forkOptions)
223
224 const onExit = function () {
225 return rej(new Error('Process exited'))
226 }
227
228 this.app.on('exit', onExit)
229
216 this.app.stdout.on('data', function onStdout (data) { 230 this.app.stdout.on('data', function onStdout (data) {
217 let dontContinue = false 231 let dontContinue = false
218 232
@@ -241,6 +255,7 @@ export class PeerTubeServer {
241 console.log(data.toString()) 255 console.log(data.toString())
242 } else { 256 } else {
243 self.app.stdout.removeListener('data', onStdout) 257 self.app.stdout.removeListener('data', onStdout)
258 self.app.removeListener('exit', onExit)
244 } 259 }
245 260
246 process.on('exit', () => { 261 process.on('exit', () => {
@@ -365,5 +380,6 @@ export class PeerTubeServer {
365 this.login = new LoginCommand(this) 380 this.login = new LoginCommand(this)
366 this.users = new UsersCommand(this) 381 this.users = new UsersCommand(this)
367 this.videos = new VideosCommand(this) 382 this.videos = new VideosCommand(this)
383 this.objectStorage = new ObjectStorageCommand(this)
368 } 384 }
369} 385}