diff options
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 46 |
1 files changed, 26 insertions, 20 deletions
@@ -32,6 +32,7 @@ if (miss.length !== 0) { | |||
32 | // ----------- PeerTube modules ----------- | 32 | // ----------- PeerTube modules ----------- |
33 | const customValidators = require('./server/helpers/custom-validators') | 33 | const customValidators = require('./server/helpers/custom-validators') |
34 | const installer = require('./server/initializers/installer') | 34 | const installer = require('./server/initializers/installer') |
35 | const migrator = require('./server/initializers/migrator') | ||
35 | const mongoose = require('mongoose') | 36 | const mongoose = require('mongoose') |
36 | const routes = require('./server/controllers') | 37 | const routes = require('./server/controllers') |
37 | const utils = require('./server/helpers/utils') | 38 | const utils = require('./server/helpers/utils') |
@@ -127,31 +128,36 @@ app.use(function (err, req, res, next) { | |||
127 | installer.installApplication(function (err) { | 128 | installer.installApplication(function (err) { |
128 | if (err) throw err | 129 | if (err) throw err |
129 | 130 | ||
130 | // Create/activate the webtorrent module | 131 | // Run the migration scripts if needed |
131 | webtorrent.create(function () { | 132 | migrator.migrate(function (err) { |
132 | function cleanForExit () { | 133 | if (err) throw err |
133 | utils.cleanForExit(webtorrent.app) | ||
134 | } | ||
135 | 134 | ||
136 | function exitGracefullyOnSignal () { | 135 | // Create/activate the webtorrent module |
137 | process.exit(-1) | 136 | webtorrent.create(function () { |
138 | } | 137 | function cleanForExit () { |
138 | utils.cleanForExit(webtorrent.app) | ||
139 | } | ||
139 | 140 | ||
140 | process.on('exit', cleanForExit) | 141 | function exitGracefullyOnSignal () { |
141 | process.on('SIGINT', exitGracefullyOnSignal) | 142 | process.exit(-1) |
142 | process.on('SIGTERM', exitGracefullyOnSignal) | 143 | } |
143 | 144 | ||
144 | // ----------- Make the server listening ----------- | 145 | process.on('exit', cleanForExit) |
145 | server.listen(port, function () { | 146 | process.on('SIGINT', exitGracefullyOnSignal) |
146 | // Activate the pool requests | 147 | process.on('SIGTERM', exitGracefullyOnSignal) |
147 | Request.activate() | ||
148 | 148 | ||
149 | Video.seedAllExisting(function (err) { | 149 | // ----------- Make the server listening ----------- |
150 | if (err) throw err | 150 | server.listen(port, function () { |
151 | // Activate the pool requests | ||
152 | Request.activate() | ||
151 | 153 | ||
152 | logger.info('Seeded all the videos') | 154 | Video.seedAllExisting(function (err) { |
153 | logger.info('Server listening on port %d', port) | 155 | if (err) throw err |
154 | app.emit('ready') | 156 | |
157 | logger.info('Seeded all the videos') | ||
158 | logger.info('Server listening on port %d', port) | ||
159 | app.emit('ready') | ||
160 | }) | ||
155 | }) | 161 | }) |
156 | }) | 162 | }) |
157 | }) | 163 | }) |