Fix status on shutdown (#18010)

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
Co-authored-by: Brainslug <tim@brainslug.nl>
This commit is contained in:
Nitwel
2023-04-05 16:50:15 +02:00
committed by GitHub
parent 8c0ac96358
commit 3219bfe38f
4 changed files with 25 additions and 10 deletions

View File

@@ -226,6 +226,7 @@ const defaults: Record<string, any> = {
REFRESH_TOKEN_COOKIE_NAME: 'directus_refresh_token',
LOGIN_STALL_TIME: 500,
SERVER_SHUTDOWN_TIMEOUT: 1000,
ROOT_REDIRECT: './admin',
@@ -310,6 +311,8 @@ const typeMap: Record<string, string> = {
FILE_METADATA_ALLOW_LIST: 'array',
GRAPHQL_INTROSPECTION: 'boolean',
SERVER_SHUTDOWN_TIMEOUT: 'number',
};
let env: Record<string, any> = {

View File

@@ -14,6 +14,8 @@ import env from './env.js';
import logger from './logger.js';
import { getConfigFromEnv } from './utils/get-config-from-env.js';
export let SERVER_ONLINE = true;
export async function createServer(): Promise<http.Server> {
const server = http.createServer(await createApp());
@@ -82,7 +84,10 @@ export async function createServer(): Promise<http.Server> {
});
const terminusOptions: TerminusOptions = {
timeout: 1000,
timeout:
env['SERVER_SHUTDOWN_TIMEOUT'] >= 0 && env['SERVER_SHUTDOWN_TIMEOUT'] < Infinity
? env['SERVER_SHUTDOWN_TIMEOUT']
: 1000,
signals: ['SIGINT', 'SIGTERM', 'SIGHUP'],
beforeShutdown,
onSignal,
@@ -97,6 +102,7 @@ export async function createServer(): Promise<http.Server> {
if (env['NODE_ENV'] !== 'development') {
logger.info('Shutting down...');
}
SERVER_ONLINE = false;
}
async function onSignal() {

View File

@@ -1,11 +1,10 @@
import type { Knex } from 'knex';
import { merge } from 'lodash-es';
import os from 'os';
import { performance } from 'perf_hooks';
import type { Accountability, SchemaOverview } from '@directus/types';
import { toArray } from '@directus/utils';
import type { Knex } from 'knex';
import { merge } from 'lodash-es';
import { Readable } from 'node:stream';
import { version } from '../utils/package.js';
import os from 'os';
import { performance } from 'perf_hooks';
import { getCache } from '../cache.js';
import getDatabase, { hasDatabaseConnection } from '../database/index.js';
import env from '../env.js';
@@ -13,9 +12,11 @@ import logger from '../logger.js';
import getMailer from '../mailer.js';
import { rateLimiterGlobal } from '../middleware/rate-limiter-global.js';
import { rateLimiter } from '../middleware/rate-limiter-ip.js';
import { SERVER_ONLINE } from '../server.js';
import { getStorage } from '../storage/index.js';
import type { AbstractServiceOptions } from '../types/index.js';
import { getOSInfo } from '../utils/get-os-info.js';
import { version } from '../utils/package.js';
import { SettingsService } from './settings.js';
export class ServerService {
@@ -136,6 +137,10 @@ export class ServerService {
),
};
if (SERVER_ONLINE === false) {
data.status = 'error';
}
for (const [service, healthData] of Object.entries(data.checks)) {
for (const healthCheck of healthData) {
if (healthCheck.status === 'warn' && data.status === 'ok') {