diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2018-05-14 17:51:15 +0200 |
---|---|---|
committer | Rigel Kent <par@rigelk.eu> | 2018-07-14 15:00:56 +0200 |
commit | 19f7b248d88805e6595b671a7447b0ba5e1451fa (patch) | |
tree | 2b58f538411c8f1d3cffaeef0e63758a7b0b050f | |
parent | 4503cb2a894d9fb2b838cab0a9af8b3923e18a56 (diff) | |
download | PeerTube-19f7b248d88805e6595b671a7447b0ba5e1451fa.tar.gz PeerTube-19f7b248d88805e6595b671a7447b0ba5e1451fa.tar.zst PeerTube-19f7b248d88805e6595b671a7447b0ba5e1451fa.zip |
adding redis unix connection
-rw-r--r-- | config/default.yaml | 2 | ||||
-rw-r--r-- | config/production.yaml.example | 4 | ||||
-rw-r--r-- | server/initializers/checker.ts | 14 | ||||
-rw-r--r-- | server/initializers/constants.ts | 9 | ||||
-rw-r--r-- | server/lib/job-queue/job-queue.ts | 8 | ||||
-rw-r--r-- | server/lib/redis.ts | 16 |
6 files changed, 36 insertions, 17 deletions
diff --git a/config/default.yaml b/config/default.yaml index 88a2f2aab..9a9b5833f 100644 --- a/config/default.yaml +++ b/config/default.yaml | |||
@@ -23,6 +23,8 @@ database: | |||
23 | username: 'peertube' | 23 | username: 'peertube' |
24 | password: 'peertube' | 24 | password: 'peertube' |
25 | 25 | ||
26 | # You can also specify a 'socket' path to a unix socket but first need to | ||
27 | # comment out hostname and port | ||
26 | redis: | 28 | redis: |
27 | hostname: 'localhost' | 29 | hostname: 'localhost' |
28 | port: 6379 | 30 | port: 6379 |
diff --git a/config/production.yaml.example b/config/production.yaml.example index ac5e2a739..a4c80b1f1 100644 --- a/config/production.yaml.example +++ b/config/production.yaml.example | |||
@@ -23,6 +23,8 @@ database: | |||
23 | password: 'peertube' | 23 | password: 'peertube' |
24 | 24 | ||
25 | # Redis server for short time storage | 25 | # Redis server for short time storage |
26 | # You can also specify a 'socket' path to a unix socket but first need to | ||
27 | # comment out hostname and port | ||
26 | redis: | 28 | redis: |
27 | hostname: 'localhost' | 29 | hostname: 'localhost' |
28 | port: 6379 | 30 | port: 6379 |
@@ -124,4 +126,4 @@ services: | |||
124 | # If true, a video player will be embedded in the Twitter feed on PeerTube video share | 126 | # If true, a video player will be embedded in the Twitter feed on PeerTube video share |
125 | # If false, we use an image link card that will redirect on your PeerTube instance | 127 | # If false, we use an image link card that will redirect on your PeerTube instance |
126 | # Test on https://cards-dev.twitter.com/validator to see if you are whitelisted | 128 | # Test on https://cards-dev.twitter.com/validator to see if you are whitelisted |
127 | whitelisted: false \ No newline at end of file | 129 | whitelisted: false |
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts index d5402098f..52a1aeb50 100644 --- a/server/initializers/checker.ts +++ b/server/initializers/checker.ts | |||
@@ -44,7 +44,6 @@ function checkMissedConfig () { | |||
44 | 'webserver.https', 'webserver.hostname', 'webserver.port', | 44 | 'webserver.https', 'webserver.hostname', 'webserver.port', |
45 | 'trust_proxy', | 45 | 'trust_proxy', |
46 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', | 46 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', |
47 | 'redis.hostname', 'redis.port', 'redis.auth', 'redis.db', | ||
48 | 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address', | 47 | 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address', |
49 | 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache', | 48 | 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache', |
50 | 'log.level', | 49 | 'log.level', |
@@ -56,6 +55,12 @@ function checkMissedConfig () { | |||
56 | 'instance.default_nsfw_policy', 'instance.robots', | 55 | 'instance.default_nsfw_policy', 'instance.robots', |
57 | 'services.twitter.username', 'services.twitter.whitelisted' | 56 | 'services.twitter.username', 'services.twitter.whitelisted' |
58 | ] | 57 | ] |
58 | const requiredAlternatives = [ | ||
59 | [ // set | ||
60 | ['redis.hostname', 'redis.port'], // alternative | ||
61 | ['redis.socket'] | ||
62 | ] | ||
63 | ] | ||
59 | const miss: string[] = [] | 64 | const miss: string[] = [] |
60 | 65 | ||
61 | for (const key of required) { | 66 | for (const key of required) { |
@@ -64,6 +69,13 @@ function checkMissedConfig () { | |||
64 | } | 69 | } |
65 | } | 70 | } |
66 | 71 | ||
72 | const missingAlternatives = requiredAlternatives.filter( | ||
73 | set => !set.find(alternative => !alternative.find(key => !config.has(key))) | ||
74 | ) | ||
75 | |||
76 | missingAlternatives | ||
77 | .forEach(set => set[0].forEach(key => miss.push(key))) | ||
78 | |||
67 | return miss | 79 | return miss |
68 | } | 80 | } |
69 | 81 | ||
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 6173e1298..c5bc886d8 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -116,10 +116,11 @@ const CONFIG = { | |||
116 | PASSWORD: config.get<string>('database.password') | 116 | PASSWORD: config.get<string>('database.password') |
117 | }, | 117 | }, |
118 | REDIS: { | 118 | REDIS: { |
119 | HOSTNAME: config.get<string>('redis.hostname'), | 119 | HOSTNAME: config.has('redis.hostname') ? config.get<string>('redis.hostname') : null, |
120 | PORT: config.get<number>('redis.port'), | 120 | PORT: config.has('redis.port') ? config.get<number>('redis.port') : null, |
121 | AUTH: config.get<string>('redis.auth'), | 121 | SOCKET: config.has('redis.socket') ? config.get<string>('redis.socket') : null, |
122 | DB: config.get<number>('redis.db') | 122 | AUTH: config.has('redis.auth') ? config.get<string>('redis.auth') : null, |
123 | DB: config.has('redis.db') ? config.get<number>('redis.db') : null | ||
123 | }, | 124 | }, |
124 | SMTP: { | 125 | SMTP: { |
125 | HOSTNAME: config.get<string>('smtp.hostname'), | 126 | HOSTNAME: config.get<string>('smtp.hostname'), |
diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts index 77aaa7fa8..1b46180e8 100644 --- a/server/lib/job-queue/job-queue.ts +++ b/server/lib/job-queue/job-queue.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import * as Bull from 'bull' | 1 | import * as Bull from 'bull' |
2 | import { JobState, JobType } from '../../../shared/models' | 2 | import { JobState, JobType } from '../../../shared/models' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { Redis } from '../redis' | ||
4 | import { CONFIG, JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_REQUEST_TTL } from '../../initializers' | 5 | import { CONFIG, JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_REQUEST_TTL } from '../../initializers' |
5 | import { ActivitypubHttpBroadcastPayload, processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast' | 6 | import { ActivitypubHttpBroadcastPayload, processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast' |
6 | import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' | 7 | import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' |
@@ -63,12 +64,7 @@ class JobQueue { | |||
63 | this.jobRedisPrefix = 'bull-' + CONFIG.WEBSERVER.HOST | 64 | this.jobRedisPrefix = 'bull-' + CONFIG.WEBSERVER.HOST |
64 | const queueOptions = { | 65 | const queueOptions = { |
65 | prefix: this.jobRedisPrefix, | 66 | prefix: this.jobRedisPrefix, |
66 | redis: { | 67 | redis: Redis.getRedisClient() |
67 | host: CONFIG.REDIS.HOSTNAME, | ||
68 | port: CONFIG.REDIS.PORT, | ||
69 | auth: CONFIG.REDIS.AUTH, | ||
70 | db: CONFIG.REDIS.DB | ||
71 | } | ||
72 | } | 68 | } |
73 | 69 | ||
74 | for (const handlerName of Object.keys(handlers)) { | 70 | for (const handlerName of Object.keys(handlers)) { |
diff --git a/server/lib/redis.ts b/server/lib/redis.ts index 78b28986a..06a340060 100644 --- a/server/lib/redis.ts +++ b/server/lib/redis.ts | |||
@@ -24,11 +24,7 @@ class Redis { | |||
24 | if (this.initialized === true) return | 24 | if (this.initialized === true) return |
25 | this.initialized = true | 25 | this.initialized = true |
26 | 26 | ||
27 | this.client = createClient({ | 27 | this.client = createClient(Redis.getRedisClient()) |
28 | host: CONFIG.REDIS.HOSTNAME, | ||
29 | port: CONFIG.REDIS.PORT, | ||
30 | db: CONFIG.REDIS.DB | ||
31 | }) | ||
32 | 28 | ||
33 | this.client.on('error', err => { | 29 | this.client.on('error', err => { |
34 | logger.error('Error in Redis client.', { err }) | 30 | logger.error('Error in Redis client.', { err }) |
@@ -42,6 +38,16 @@ class Redis { | |||
42 | this.prefix = 'redis-' + CONFIG.WEBSERVER.HOST + '-' | 38 | this.prefix = 'redis-' + CONFIG.WEBSERVER.HOST + '-' |
43 | } | 39 | } |
44 | 40 | ||
41 | static getRedisClient () { | ||
42 | return Object.assign({}, | ||
43 | (CONFIG.REDIS.AUTH && CONFIG.REDIS.AUTH != null) ? { password: CONFIG.REDIS.AUTH } : {}, | ||
44 | (CONFIG.REDIS.DB) ? { db: CONFIG.REDIS.DB } : {}, | ||
45 | (CONFIG.REDIS.HOSTNAME && CONFIG.REDIS.PORT) ? | ||
46 | { host: CONFIG.REDIS.HOSTNAME, port: CONFIG.REDIS.PORT } : | ||
47 | { path: CONFIG.REDIS.SOCKET } | ||
48 | ) | ||
49 | } | ||
50 | |||
45 | async setResetPasswordVerificationString (userId: number) { | 51 | async setResetPasswordVerificationString (userId: number) { |
46 | const generatedString = await generateRandomString(32) | 52 | const generatedString = await generateRandomString(32) |
47 | 53 | ||