ActivityPub-federated video streaming platform using P2P directly in your web browser
adding redis unix connection
Rigel Kent19f7b248d888
diff --git a/config/default.yaml b/config/default.yamlindex 88a2f2aab3..9a9b5833f7 100644--- a/config/default.yaml+++ b/config/default.yaml@@ -23,6 +23,8 @@ database:username: 'peertube'password: 'peertube'+# You can also specify a 'socket' path to a unix socket but first need to+# comment out hostname and portredis:hostname: 'localhost'port: 6379diff --git a/config/production.yaml.example b/config/production.yaml.exampleindex ac5e2a7391..a4c80b1f1b 100644--- a/config/production.yaml.example+++ b/config/production.yaml.example@@ -23,6 +23,8 @@ database:password: 'peertube'# Redis server for short time storage+# You can also specify a 'socket' path to a unix socket but first need to+# comment out hostname and portredis:hostname: 'localhost'port: 6379@@ -124,4 +126,4 @@ services:# If true, a video player will be embedded in the Twitter feed on PeerTube video share# If false, we use an image link card that will redirect on your PeerTube instance# Test on https://cards-dev.twitter.com/validator to see if you are whitelisted- whitelisted: false\ No newline at end of file+ whitelisted: falsediff --git a/server/initializers/checker.ts b/server/initializers/checker.tsindex d5402098f3..52a1aeb50b 100644--- a/server/initializers/checker.ts+++ b/server/initializers/checker.ts@@ -44,7 +44,6 @@ function checkMissedConfig () {'webserver.https', 'webserver.hostname', 'webserver.port','trust_proxy','database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password',- 'redis.hostname', 'redis.port', 'redis.auth', 'redis.db','smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address','storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache','log.level',@@ -56,6 +55,12 @@ function checkMissedConfig () {'instance.default_nsfw_policy', 'instance.robots','services.twitter.username', 'services.twitter.whitelisted']+ const requiredAlternatives = [+ [ // set+ ['redis.hostname', 'redis.port'], // alternative+ ['redis.socket']+ ]+ ]const miss: string[] = []for (const key of required) {@@ -64,6 +69,13 @@ function checkMissedConfig () {}}+ const missingAlternatives = requiredAlternatives.filter(+ set => !set.find(alternative => !alternative.find(key => !config.has(key)))+ )++ missingAlternatives+ .forEach(set => set[0].forEach(key => miss.push(key)))+return miss}diff --git a/server/initializers/constants.ts b/server/initializers/constants.tsindex 6173e1298d..c5bc886d8d 100644--- a/server/initializers/constants.ts+++ b/server/initializers/constants.ts@@ -116,10 +116,11 @@ const CONFIG = {PASSWORD: config.get<string>('database.password')},REDIS: {- HOSTNAME: config.get<string>('redis.hostname'),- PORT: config.get<number>('redis.port'),- AUTH: config.get<string>('redis.auth'),- DB: config.get<number>('redis.db')+ HOSTNAME: config.has('redis.hostname') ? config.get<string>('redis.hostname') : null,+ PORT: config.has('redis.port') ? config.get<number>('redis.port') : null,+ SOCKET: config.has('redis.socket') ? config.get<string>('redis.socket') : null,+ AUTH: config.has('redis.auth') ? config.get<string>('redis.auth') : null,+ DB: config.has('redis.db') ? config.get<number>('redis.db') : null},SMTP: {HOSTNAME: config.get<string>('smtp.hostname'),diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.tsindex 77aaa7fa8a..1b46180e8e 100644--- a/server/lib/job-queue/job-queue.ts+++ b/server/lib/job-queue/job-queue.ts@@ -1,6 +1,7 @@import * as Bull from 'bull'import { JobState, JobType } from '../../../shared/models'import { logger } from '../../helpers/logger'+import { Redis } from '../redis'import { CONFIG, JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_REQUEST_TTL } from '../../initializers'import { ActivitypubHttpBroadcastPayload, processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast'import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher'@@ -63,12 +64,7 @@ class JobQueue {this.jobRedisPrefix = 'bull-' + CONFIG.WEBSERVER.HOSTconst queueOptions = {prefix: this.jobRedisPrefix,- redis: {- host: CONFIG.REDIS.HOSTNAME,- port: CONFIG.REDIS.PORT,- auth: CONFIG.REDIS.AUTH,- db: CONFIG.REDIS.DB- }+ redis: Redis.getRedisClient()}for (const handlerName of Object.keys(handlers)) {diff --git a/server/lib/redis.ts b/server/lib/redis.tsindex 78b28986a0..06a3400601 100644--- a/server/lib/redis.ts+++ b/server/lib/redis.ts@@ -24,11 +24,7 @@ class Redis {if (this.initialized === true) returnthis.initialized = true- this.client = createClient({- host: CONFIG.REDIS.HOSTNAME,- port: CONFIG.REDIS.PORT,- db: CONFIG.REDIS.DB- })+ this.client = createClient(Redis.getRedisClient())this.client.on('error', err => {logger.error('Error in Redis client.', { err })@@ -42,6 +38,16 @@ class Redis {this.prefix = 'redis-' + CONFIG.WEBSERVER.HOST + '-'}+ static getRedisClient () {+ return Object.assign({},+ (CONFIG.REDIS.AUTH && CONFIG.REDIS.AUTH != null) ? { password: CONFIG.REDIS.AUTH } : {},+ (CONFIG.REDIS.DB) ? { db: CONFIG.REDIS.DB } : {},+ (CONFIG.REDIS.HOSTNAME && CONFIG.REDIS.PORT) ?+ { host: CONFIG.REDIS.HOSTNAME, port: CONFIG.REDIS.PORT } :+ { path: CONFIG.REDIS.SOCKET }+ )+ }+async setResetPasswordVerificationString (userId: number) {const generatedString = await generateRandomString(32)