A small notice about recent @osjs/server update


#1

Hi All,

The process exit handling has now been moved from the core to the distro since version 3.0.55 of @osjs/server.

So with the latest changes you’ll have to update your bootstrap script in order for the process to exit gracefully (without the update you’ll have to force exit, aka Ctrl-C at least twice, or in some cases manually stop a running docker container).

Below are a comparison of the src/server/index.js file before and after the change. The difference is that some deprecated event handlers have been removed, and the remaining ones now uses a higher order function to call the shutdown procedure.

Before

const {
  Core,
  CoreServiceProvider,
  PackageServiceProvider,
  VFSServiceProvider,
  AuthServiceProvider,
  SettingsServiceProvider
} = require('@osjs/server');

const config = require('./config.js');
const osjs = new Core(config, {});

osjs.register(CoreServiceProvider, {before: true});
osjs.register(PackageServiceProvider);
osjs.register(VFSServiceProvider);
osjs.register(AuthServiceProvider);
osjs.register(SettingsServiceProvider);

process.on('SIGTERM', () => osjs.destroy());
process.on('SIGINT', () => osjs.destroy());
process.on('exit', () => osjs.destroy());
process.on('uncaughtException', e => console.error(e));
process.on('unhandledRejection', e => console.error(e));

osjs.boot()
  .catch(err => {
    console.error(err);
    process.exit(1);
  });

After

const {
  Core,
  CoreServiceProvider,
  PackageServiceProvider,
  VFSServiceProvider,
  AuthServiceProvider,
  SettingsServiceProvider
} = require('@osjs/server');

const config = require('./config.js');
const osjs = new Core(config, {});

osjs.register(CoreServiceProvider, {before: true});
osjs.register(PackageServiceProvider);
osjs.register(VFSServiceProvider);
osjs.register(AuthServiceProvider);
osjs.register(SettingsServiceProvider);

const shutdown = signal => (error) => {
  if (error instanceof Error) {
    console.error(error);
  }

  osjs.destroy(() => process.exit(signal));
};

process.on('SIGTERM', shutdown(0));
process.on('SIGINT', shutdown(0));
process.on('exit', shutdown(0));

osjs.boot().catch(shutdown(1));