import { access , ensureDir } from "fs-extra" ; import { dirname , join } from "path" ; import Environment from "./common/Environment" ; import { BlobServerFactory } from "./blob/BlobServerFactory" ; import * as Logger from "./common/Logger" ; import QueueConfiguration from "./queue/QueueConfiguration" ; import QueueServer from "./queue/QueueServer" ; import { DEFAULT_QUEUE_EXTENT_LOKI_DB_PATH , DEFAULT_QUEUE_LOKI_DB_PATH , DEFAULT_QUEUE_PERSISTENCE_ARRAY , DEFAULT_QUEUE_PERSISTENCE_PATH } from "./queue/utils/constants" ; import SqlBlobServer from "./blob/SqlBlobServer" ; import BlobServer from "./blob/BlobServer" ; import TableConfiguration from "./table/TableConfiguration" ; import TableServer from "./table/TableServer" ; import { DEFAULT_TABLE_LOKI_DB_PATH } from "./table/utils/constants" ; function shutdown ( blobServer , queueServer , tableServer ) { const blobBeforeCloseMessage = `Azurite Blob service is closing...` ; const blobAfterCloseMessage = `Azurite Blob service successfully closed` ; const queueBeforeCloseMessage = `Azurite Queue service is closing...` ; const queueAfterCloseMessage = `Azurite Queue service successfully closed` ; const tableBeforeCloseMessage = `Azurite Table service is closing...` ; const tableAfterCloseMessage = `Azurite Table service successfully closed` ; console . log ( blobBeforeCloseMessage ) ; blobServer . close ( ) . then ( ( ) => { console . log ( blobAfterCloseMessage ) ; } ) ; console . log ( queueBeforeCloseMessage ) ; queueServer . close ( ) . then ( ( ) => { console . log ( queueAfterCloseMessage ) ; } ) ; console . log ( tableBeforeCloseMessage ) ; tableServer . close ( ) . then ( ( ) => { console . log ( tableAfterCloseMessage ) ; } ) ; } /**
 * Entry for Azurite services.
 */ async function main ( ) { const env = new Environment ( ) ; const location = await env . location ( ) ; await ensureDir ( location ) ; await access ( location ) ; const debugFilePath = await env . debug ( ) ; if ( debugFilePath !== undefined ) { await ensureDir ( dirname ( debugFilePath ! ) ) ; await access ( dirname ( debugFilePath ! ) ) ; } const blobServerFactory = new BlobServerFactory ( ) ; const blobServer = await blobServerFactory . createServer ( env ) ; const blobConfig = blobServer . config ; DEFAULT_QUEUE_PERSISTENCE_ARRAY [ 0 ] . locationPath = join ( location , DEFAULT_QUEUE_PERSISTENCE_PATH ) ; const queueConfig = new QueueConfiguration ( env . queueHost ( ) , env . queuePort ( ) , join ( location , DEFAULT_QUEUE_LOKI_DB_PATH ) , join ( location , DEFAULT_QUEUE_EXTENT_LOKI_DB_PATH ) , DEFAULT_QUEUE_PERSISTENCE_ARRAY , ! env . silent ( ) , undefined , env . debug ( ) !== undefined , await env . debug ( ) , env . loose ( ) , env . skipApiVersionCheck ( ) , env . cert ( ) , env . key ( ) , env . pwd ( ) , env . oauth ( ) , env . disableProductStyleUrl ( ) ) ; const tableConfig = new TableConfiguration ( env . tableHost ( ) , env . tablePort ( ) , join ( location , DEFAULT_TABLE_LOKI_DB_PATH ) , env . debug ( ) !== undefined , ! env . silent ( ) , undefined , await env . debug ( ) , env . loose ( ) , env . skipApiVersionCheck ( ) , env . cert ( ) , env . key ( ) , env . pwd ( ) , env . oauth ( ) , env . disableProductStyleUrl ( ) ) ; Logger . configLogger ( blobConfig . enableDebugLog , blobConfig . debugLogFilePath ) ; const queueServer = new QueueServer ( queueConfig ) ; const tableServer = new TableServer ( tableConfig ) ; console . log ( `Azurite Blob service is starting at ${ blobConfig . getHttpServerAddress ( ) }` ) ; await blobServer . start ( ) ; console . log ( `Azurite Blob service is successfully listening at ${ blobServer . getHttpServerAddress ( ) }` ) ; console . log ( `Azurite Queue service is starting at ${ queueConfig . getHttpServerAddress ( ) }` ) ; await queueServer . start ( ) ; console . log ( `Azurite Queue service is successfully listening at ${ queueServer . getHttpServerAddress ( ) }` ) ; console . log ( `Azurite Table service is starting at ${ tableConfig . getHttpServerAddress ( ) }` ) ; await tableServer . start ( ) ; console . log ( `Azurite Table service is successfully listening at ${ tableServer . getHttpServerAddress ( ) }` ) ; process . once ( "message" , ( msg ) => { if ( msg === "shutdown" ) { shutdown ( blobServer , queueServer , tableServer ) ; } } ) . once ( "SIGINT" , ( ) => shutdown ( blobServer , queueServer , tableServer ) ) . once ( "SIGTERM" , ( ) => shutdown ( blobServer , queueServer , tableServer ) ) ; } main ( ) . catch ( ( err ) => { console . error ( `Exit due to unhandled error: ${ err . message }` ) ; process . exit ( 1 ) ; } ) ;