mirror of
https://github.com/badges/shields.git
synced 2025-04-17 08:37:04 +03:00
* graceful shutdown The main entrypoint now handles the SIGTERM signal and stops the server. * Don't call process.exit on shutdown That is not graceful in nodejs, see https://kostasbariotis.com/why-you-should-not-use-process-exit/
71 lines
1.9 KiB
JavaScript
71 lines
1.9 KiB
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import { fileURLToPath } from 'url'
|
|
import configModule from 'config'
|
|
import * as Sentry from '@sentry/node'
|
|
import Server from './core/server/server.js'
|
|
|
|
// Set up Sentry reporting as early in the process as possible.
|
|
const config = configModule.util.toObject()
|
|
const disabledIntegrations = ['Console', 'Http']
|
|
Sentry.init({
|
|
dsn: process.env.SENTRY_DSN || config.private.sentry_dsn,
|
|
integrations: integrations => {
|
|
const filtered = integrations.filter(
|
|
integration => !disabledIntegrations.includes(integration.name),
|
|
)
|
|
if (filtered.length !== integrations.length - disabledIntegrations.length) {
|
|
throw Error(
|
|
`An error occurred while filtering integrations. The following inetgrations were found: ${integrations.map(
|
|
({ name }) => name,
|
|
)}`,
|
|
)
|
|
}
|
|
return filtered
|
|
},
|
|
})
|
|
|
|
if (+process.argv[2]) {
|
|
config.public.bind.port = +process.argv[2]
|
|
}
|
|
if (process.argv[3]) {
|
|
config.public.bind.address = process.argv[3]
|
|
}
|
|
|
|
console.log('Configuration:')
|
|
console.dir(config.public, { depth: null })
|
|
|
|
if (fs.existsSync('.env')) {
|
|
console.error(
|
|
'Legacy .env file found. It should be deleted and replaced with environment variables or config/local.yml',
|
|
)
|
|
process.exit(1)
|
|
}
|
|
|
|
if (config.private.redis_url != null) {
|
|
console.error(
|
|
'RedisTokenPersistence has been removed. Migrate to SqlTokenPersistence',
|
|
)
|
|
process.exit(1)
|
|
}
|
|
|
|
const legacySecretsPath = path.join(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
'private',
|
|
'secret.json',
|
|
)
|
|
if (fs.existsSync(legacySecretsPath)) {
|
|
console.error(
|
|
`Legacy secrets file found at ${legacySecretsPath}. It should be deleted and secrets replaced with environment variables or config/local.yml`,
|
|
)
|
|
process.exit(1)
|
|
}
|
|
export const server = new Server(config)
|
|
|
|
process.on('SIGTERM', async () => {
|
|
console.log('SIGTERM received, shutting down...')
|
|
await server.stop()
|
|
})
|
|
|
|
await server.start()
|