server: Refine process lifetime management

Define states and use them to properly handle multiple calls to
`start()`, `stop()`, and `exit()`. (Multiple calls to `exit()` can
happen if there is an uncaught exception or signal during shutdown.)

This should also make it easier to add support for cleanly restarting
the server after a shutdown (for tests or via an `/admin` page).
This commit is contained in:
Richard Hansen 2020-12-22 01:08:50 -05:00 committed by John McLear
parent 725023fe58
commit ecdb105bfe
2 changed files with 108 additions and 21 deletions

View file

@ -50,10 +50,10 @@ exports.init = async function () {
after(async function () {
webaccess.authnFailureDelayMs = backups.authnFailureDelayMs;
await server.stop();
// Note: This does not unset settings that were added.
Object.assign(settings, backups.settings);
log4js.setGlobalLogLevel(logLevel);
await server.exit();
});
return exports.agent;