fix: 🚑 Sleep process instead of exiting it on error

Avoids Docker's auto-restart policy from causing infinite reboots and hanging the system
This commit is contained in:
Jesse Wierzbinski 2024-06-13 23:44:46 -10:00
parent 7ba0eb82f1
commit c764cc044d
No known key found for this signature in database
4 changed files with 24 additions and 7 deletions

View file

@ -34,7 +34,9 @@ export const setupDatabase = async (
"Database", "Database",
"Failed to connect to database. Please check your configuration.", "Failed to connect to database. Please check your configuration.",
); );
process.exit();
// Hang until Ctrl+C is pressed
await Bun.sleep(Number.POSITIVE_INFINITY);
} }
// Migrate the database // Migrate the database
@ -52,7 +54,9 @@ export const setupDatabase = async (
"Database", "Database",
"Failed to migrate database. Please check your configuration.", "Failed to migrate database. Please check your configuration.",
); );
process.exit();
// Hang until Ctrl+C is pressed
await Bun.sleep(Number.POSITIVE_INFINITY);
} }
info && (await logger.log(LogLevel.Info, "Database", "Database migrated")); info && (await logger.log(LogLevel.Info, "Database", "Database migrated"));

View file

@ -38,6 +38,10 @@ if (config.meilisearch.enabled) {
await connectMeili(dualServerLogger); await connectMeili(dualServerLogger);
} }
process.on("SIGINT", () => {
process.exit();
});
// Check if database is reachable // Check if database is reachable
const postCount = await Note.getCount(); const postCount = await Note.getCount();
@ -73,7 +77,9 @@ if (isEntry) {
"Server", "Server",
chalk.gray(`${privateKey};${publicKey}`), chalk.gray(`${privateKey};${publicKey}`),
); );
process.exit();
// Hang until Ctrl+C is pressed
await Bun.sleep(Number.POSITIVE_INFINITY);
} }
// Try and import the key // Try and import the key
@ -104,7 +110,9 @@ if (isEntry) {
"Server", "Server",
"The JWT key could not be imported! You may generate a new one by removing the old one from the config and restarting the server (this will invalidate all current JWTs).", "The JWT key could not be imported! You may generate a new one by removing the old one from the config and restarting the server (this will invalidate all current JWTs).",
); );
process.exit();
// Hang until Ctrl+C is pressed
await Bun.sleep(Number.POSITIVE_INFINITY);
} }
if ( if (
@ -142,7 +150,8 @@ if (isEntry) {
`Generated key: ${chalk.gray(base64)}`, `Generated key: ${chalk.gray(base64)}`,
); );
process.exit(); // Hang until Ctrl+C is pressed
await Bun.sleep(Number.POSITIVE_INFINITY);
} }
} }
@ -245,7 +254,8 @@ if (config.frontend.enabled) {
"Server", "Server",
`Frontend URL is not a valid URL: ${config.frontend.url}`, `Frontend URL is not a valid URL: ${config.frontend.url}`,
); );
process.exit(); // Hang until Ctrl+C is pressed
await Bun.sleep(Number.POSITIVE_INFINITY);
} }
// Check if frontend is reachable // Check if frontend is reachable

View file

@ -24,6 +24,8 @@ const parsed = await configValidator.safeParseAsync(config);
if (!parsed.success) { if (!parsed.success) {
console.error("Invalid config file:"); console.error("Invalid config file:");
console.error(fromZodError(parsed.error).message); console.error(fromZodError(parsed.error).message);
// Hang until Ctrl+C is pressed
await Bun.sleep(Number.POSITIVE_INFINITY);
process.exit(); process.exit();
} }

View file

@ -44,7 +44,8 @@ export const connectMeili = async (logger: MultiLogManager | LogManager) => {
"Meilisearch", "Meilisearch",
"Error while connecting to Meilisearch", "Error while connecting to Meilisearch",
); );
process.exit(); // Hang until Ctrl+C is pressed
await Bun.sleep(Number.POSITIVE_INFINITY);
} }
}; };