diff --git a/packages/bootstrap/cli/webpack.js b/packages/bootstrap/cli/webpack.js index b27ab54e95b..f89847906c9 100644 --- a/packages/bootstrap/cli/webpack.js +++ b/packages/bootstrap/cli/webpack.js @@ -12,6 +12,7 @@ const webpackExtensionConfig = require('../webpack/webpack.extension.conf'); const path = require('path'); const fs = require('fs-extra'); const npmCheck = require('npm-checky'); +const chalk = require('chalk'); const interactiveUpdate = require('npm-checky/lib/out/interactive-update'); const resolve = dir => path.resolve(process.cwd(), dir); @@ -75,7 +76,10 @@ async function devServer(setAlias, checkUpgrade) { const server = new wds(devServerOptions, compiler); server.startCallback(() => { - console.log('Successfully started server on http://localhost:8000'); + console.log( + chalk.green.bold('Successfully started server on ') + + chalk.blue.bold.underline('http://localhost:8000'), + ); }); } diff --git a/server/server.js b/server/server.js index de0ddd03eba..ea608944627 100644 --- a/server/server.js +++ b/server/server.js @@ -5,6 +5,7 @@ const Koa = require('koa'); const path = require('path'); +const chalk = require('chalk'); Koa.prototype.apply = function (module, ...rest) { module(this, ...rest); @@ -39,7 +40,38 @@ app.server = app.listen(global.PORT, err => { return console.error(err); } /* eslint-disable no-console */ - console.log(`Dashboard app running at port ${global.PORT}`); + console.log(chalk.green.bold(`Dashboard app running at port ${global.PORT}`)); }); app.apply(wsProxy); + +const shutdown = () => { + console.log('Received shutdown signal. Starting graceful shutdown...'); + + // waiting for the server to shut down + app.server.close(err => { + if (err) { + console.error('Error during server shutdown:', err); + process.exit(1); + } + console.log('Server closed successfully.'); + process.exit(0); + }); + + // If shutdown times out, force quit + setTimeout(() => { + console.log('Force quitting due to shutdown timeout.'); + process.exit(1); + }, 5000); +}; + +// Capture Ctrl+C +process.on('SIGINT', () => { + console.log('\nSIGINT signal received.'); + shutdown(); +}); +// Capturing the termination signal +process.on('SIGTERM', () => { + console.log('SIGTERM signal received.'); + shutdown(); +});