import { migrate } from './server/initializers/migrator'
migrate()
.then(() => initDatabaseModels(false))
- .then(() => onDatabaseInitDone())
+ .then(() => startApplication())
+ .catch(err => {
+ logger.error('Cannot start application.', { err })
+ process.exit(-1)
+ })
// ----------- PeerTube modules -----------
import { installApplication } from './server/initializers'
// ----------- Run -----------
-function onDatabaseInitDone () {
+async function startApplication () {
const port = CONFIG.LISTEN.PORT
- installApplication()
- .then(() => {
- // ----------- Make the server listening -----------
- server.listen(port, () => {
- // Emailer initialization and then job queue initialization
- Emailer.Instance.init()
- Emailer.Instance.checkConnectionOrDie()
- .then(() => JobQueue.Instance.init())
-
- // Caches initializations
- VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE)
-
- // Enable Schedulers
- BadActorFollowScheduler.Instance.enable()
- RemoveOldJobsScheduler.Instance.enable()
-
- // Redis initialization
- Redis.Instance.init()
-
- logger.info('Server listening on port %d', port)
- logger.info('Web server: %s', CONFIG.WEBSERVER.URL)
- })
- })
+ await installApplication()
+
+ // Email initialization
+ Emailer.Instance.init()
+ await Emailer.Instance.checkConnectionOrDie()
+
+ await JobQueue.Instance.init()
+
+ // Caches initializations
+ VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE)
+
+ // Enable Schedulers
+ BadActorFollowScheduler.Instance.enable()
+ RemoveOldJobsScheduler.Instance.enable()
+
+ // Redis initialization
+ Redis.Instance.init()
+
+ // Make server listening
+ server.listen(port)
+ logger.info('Server listening on port %d', port)
+ logger.info('Web server: %s', CONFIG.WEBSERVER.URL)
}