aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'server.js')
-rw-r--r--server.js46
1 files changed, 26 insertions, 20 deletions
diff --git a/server.js b/server.js
index 8010d3e06..b8564d05a 100644
--- a/server.js
+++ b/server.js
@@ -32,6 +32,7 @@ if (miss.length !== 0) {
32// ----------- PeerTube modules ----------- 32// ----------- PeerTube modules -----------
33const customValidators = require('./server/helpers/custom-validators') 33const customValidators = require('./server/helpers/custom-validators')
34const installer = require('./server/initializers/installer') 34const installer = require('./server/initializers/installer')
35const migrator = require('./server/initializers/migrator')
35const mongoose = require('mongoose') 36const mongoose = require('mongoose')
36const routes = require('./server/controllers') 37const routes = require('./server/controllers')
37const utils = require('./server/helpers/utils') 38const utils = require('./server/helpers/utils')
@@ -127,31 +128,36 @@ app.use(function (err, req, res, next) {
127installer.installApplication(function (err) { 128installer.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 })