import { access , ensureDir } from "fs-extra" ; import { dirname , join } from "path" ; import * as Logger from "../common/Logger" ; import TableConfiguration from "./TableConfiguration" ; import TableEnvironment from "./TableEnvironment" ; import TableServer from "./TableServer" ; import { DEFAULT_TABLE_LOKI_DB_PATH } from "./utils/constants" ; /**
 * Entry for Azurite table service
 */ async function main ( ) { const env = new TableEnvironment ( ) ; 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 config = new TableConfiguration ( env . tableHost ( ) , env . tablePort ( ) , join ( location , DEFAULT_TABLE_LOKI_DB_PATH ) , ( await 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 ( config . enableDebugLog , config . debugLogFilePath ) ; const server = new TableServer ( config ) ; const beforeStartMessage = `Azurite Table service is starting on ${ config . host }:${ config . port }` ; const afterStartMessage = `Azurite Table service successfully started on ${ config . host }:${ config . port }` ; const beforeCloseMessage = `Azurite Table service is closing...` ; const afterCloseMessage = `Azurite Table service successfully closed` ; console . log ( beforeStartMessage ) ; await server . start ( ) ; console . log ( afterStartMessage ) ; process . once ( "message" , ( msg ) => { if ( msg === "shutdown" ) { console . log ( beforeCloseMessage ) ; server . close ( ) . then ( ( ) => { console . log ( afterCloseMessage ) ; } ) ; } } ) . once ( "SIGINT" , ( ) => { console . log ( beforeCloseMessage ) ; server . clean ( ) . then ( ( ) => { console . log ( afterCloseMessage ) ; } ) ; } ) ; } main ( ) . catch ( ( err ) => { console . error ( `Exiting due to an unhandled error: ${ err . message }` ) ; process . exit ( 1 ) ; } ) ;