]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/checker.js
Server: add webserver url log at startup
[github/Chocobozzz/PeerTube.git] / server / initializers / checker.js
CommitLineData
9f10b292
C
1'use strict'
2
f0f5567b 3const config = require('config')
69b0a27c 4const mongoose = require('mongoose')
37dc07b2 5
69b0a27c
C
6const Client = mongoose.model('OAuthClient')
7const User = mongoose.model('User')
9f10b292 8
f0f5567b 9const checker = {
c4403b29
C
10 checkConfig,
11 clientsExist,
12 usersExist
9f10b292
C
13}
14
15// Check the config files
16function checkConfig () {
f0f5567b 17 const required = [ 'listen.port',
3737bbaf
C
18 'webserver.https', 'webserver.hostname', 'webserver.port',
19 'database.hostname', 'database.port', 'database.suffix',
b3d92510 20 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails'
56835348 21 ]
f0f5567b 22 const miss = []
9f10b292 23
f0f5567b 24 for (const key of required) {
9f10b292
C
25 if (!config.has(key)) {
26 miss.push(key)
8c308c2b 27 }
8c308c2b
C
28 }
29
9f10b292
C
30 return miss
31}
32
37dc07b2 33function clientsExist (callback) {
69b0a27c 34 Client.list(function (err, clients) {
37dc07b2 35 if (err) return callback(err)
9f10b292 36
37dc07b2
C
37 return callback(null, clients.length !== 0)
38 })
39}
40
41function usersExist (callback) {
5c39adb7 42 User.countTotal(function (err, totalUsers) {
37dc07b2
C
43 if (err) return callback(err)
44
089ff2f2 45 return callback(null, totalUsers !== 0)
37dc07b2 46 })
9f10b292 47}
8c308c2b 48
9f10b292 49// ---------------------------------------------------------------------------
c45f7f84 50
9f10b292 51module.exports = checker