diff --git a/src/startup.ts b/src/startup.ts index 71571a9f..33de513e 100644 --- a/src/startup.ts +++ b/src/startup.ts @@ -5,6 +5,7 @@ import { Server as MongoServer, Db } from 'mongodb'; import { Server } from './server'; import { ConsoleManager } from './console/console-manager'; import { prepare } from './db-preparation'; +import * as cluster from 'cluster'; let config: Modepress.IConfig | null = null; const args = yargs.argv; @@ -52,7 +53,7 @@ catch ( err ) { /** * initialization function to prep DB and servers */ -async function initialize() { +export async function initialize() { info( `Attempting to connect to mongodb...` ); const mongoServer = new MongoServer( config!.databaseHost, config!.databasePort, config!.databaseName ); @@ -82,7 +83,9 @@ async function initialize() { new ConsoleManager().initialize(); } -// Start the server initialization -initialize().catch(( err: Error ) => { - error( err.message ).then(() => process.exit() ); -} ); \ No newline at end of file +if ( cluster.isWorker ) { + // Start the server initialization + initialize().catch(( err: Error ) => { + error( err.message ).then(() => process.exit() ); + } ); +} \ No newline at end of file