aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-09-26 22:36:36 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-09-26 22:39:58 +0200
commit00d6b0dda4b1964ab11127851c0fc7106cc0f912 (patch)
tree3759ff8c8724f85f2554c28edf5bcf58a60085cf /server.js
parent44c5275e1bdd1d4b4c23f7c423034e4293c927b3 (diff)
downloadPeerTube-00d6b0dda4b1964ab11127851c0fc7106cc0f912.tar.gz
PeerTube-00d6b0dda4b1964ab11127851c0fc7106cc0f912.tar.zst
PeerTube-00d6b0dda4b1964ab11127851c0fc7106cc0f912.zip
Add migration (for db, folders...) mechanism
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 })