]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/checker.ts
Add SQL backup/restore commands in production guide
[github/Chocobozzz/PeerTube.git] / server / initializers / checker.ts
CommitLineData
4d4e5cd4 1import * as config from 'config'
da854ddd 2import { promisify0 } from '../helpers/core-utils'
3fd3ab2d
C
3import { UserModel } from '../models/account/user'
4import { ApplicationModel } from '../models/application/application'
5import { OAuthClientModel } from '../models/oauth/oauth-client'
9f10b292 6
b65c27aa 7// Some checks on configuration files
9f10b292 8function checkConfig () {
b65c27aa
C
9 if (config.has('webserver.host')) {
10 let errorMessage = '`host` config key was renamed to `hostname` but it seems you still have a `host` key in your configuration files!'
11 errorMessage += ' Please ensure to rename your `host` configuration to `hostname`.'
12
13 return errorMessage
14 }
15
16 return null
17}
18
19// Check the config files
20function checkMissedConfig () {
f0f5567b 21 const required = [ 'listen.port',
3737bbaf 22 'webserver.https', 'webserver.hostname', 'webserver.port',
b769007f 23 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password',
3b6eaa92 24 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', 'storage.torrents', 'storage.cache',
77a5501f 25 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads', 'user.video_quota'
56835348 26 ]
69818c93 27 const miss: string[] = []
9f10b292 28
f0f5567b 29 for (const key of required) {
9f10b292
C
30 if (!config.has(key)) {
31 miss.push(key)
8c308c2b 32 }
8c308c2b
C
33 }
34
9f10b292
C
35 return miss
36}
37
e5b88539 38// Check the available codecs
3482688c 39// We get CONFIG by param to not import it in this file (import orders)
f5028693 40async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
e5b88539 41 const Ffmpeg = require('fluent-ffmpeg')
6fcd19ba
C
42 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
43
f5028693
C
44 const codecs = await getAvailableCodecsPromise()
45 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
46
47 const canEncode = [ 'libx264' ]
48 for (const codec of canEncode) {
49 if (codecs[codec] === undefined) {
50 throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
51 }
52
53 if (codecs[codec].canEncode !== true) {
54 throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg')
55 }
56 }
e5b88539
C
57}
58
3482688c 59// We get db by param to not import it in this file (import orders)
3fd3ab2d
C
60async function clientsExist () {
61 const totalClients = await OAuthClientModel.countTotal()
f5028693
C
62
63 return totalClients !== 0
37dc07b2
C
64}
65
3482688c 66// We get db by param to not import it in this file (import orders)
3fd3ab2d
C
67async function usersExist () {
68 const totalUsers = await UserModel.countTotal()
f5028693
C
69
70 return totalUsers !== 0
9f10b292 71}
8c308c2b 72
350e31d6 73// We get db by param to not import it in this file (import orders)
3fd3ab2d
C
74async function applicationExist () {
75 const totalApplication = await ApplicationModel.countTotal()
350e31d6
C
76
77 return totalApplication !== 0
78}
79
9f10b292 80// ---------------------------------------------------------------------------
c45f7f84 81
65fcc311
C
82export {
83 checkConfig,
84 checkFFmpeg,
85 checkMissedConfig,
86 clientsExist,
350e31d6
C
87 usersExist,
88 applicationExist
65fcc311 89}