Fix request schedulers stats
[oweals/peertube.git] / server / initializers / checker.js
1 'use strict'
2
3 const config = require('config')
4
5 const db = require('./database')
6
7 const checker = {
8   checkConfig,
9   checkMissedConfig,
10   clientsExist,
11   usersExist
12 }
13
14 // Some checks on configuration files
15 function checkConfig () {
16   if (config.has('webserver.host')) {
17     let errorMessage = '`host` config key was renamed to `hostname` but it seems you still have a `host` key in your configuration files!'
18     errorMessage += ' Please ensure to rename your `host` configuration to `hostname`.'
19
20     return errorMessage
21   }
22
23   return null
24 }
25
26 // Check the config files
27 function checkMissedConfig () {
28   const required = [ 'listen.port',
29     'webserver.https', 'webserver.hostname', 'webserver.port',
30     'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password',
31     'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews',
32     'admin.email'
33   ]
34   const miss = []
35
36   for (const key of required) {
37     if (!config.has(key)) {
38       miss.push(key)
39     }
40   }
41
42   return miss
43 }
44
45 function clientsExist (callback) {
46   db.OAuthClient.countTotal(function (err, totalClients) {
47     if (err) return callback(err)
48
49     return callback(null, totalClients !== 0)
50   })
51 }
52
53 function usersExist (callback) {
54   db.User.countTotal(function (err, totalUsers) {
55     if (err) return callback(err)
56
57     return callback(null, totalUsers !== 0)
58   })
59 }
60
61 // ---------------------------------------------------------------------------
62
63 module.exports = checker