Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix process exit code #1900

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions impress.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ const impress = {
startTimer: null,
};

const exit = async (message) => {
const exit = async (message, code) => {
if (impress.finalization) return;
impress.finalization = true;
impress.console.info(message);
if (impress.logger && impress.logger.active) await impress.logger.close();
process.exit(1);
process.exit(code);
};

const logError = (type) => (error) => {
if (error.name === 'ExperimentalWarning') return;
const msg = error?.stack || error?.message || 'exit';
impress.console.error(`${type}: ${msg}`);
if (type === 'warning') return;
if (impress.initialization) exit('Can not start Application server');
if (impress.initialization) exit('Can not start Application server', 1);
};

const startWorker = async (app, kind, port, id = ++impress.lastWorkerId) => {
Expand All @@ -63,7 +63,7 @@ const startWorker = async (app, kind, port, id = ++impress.lastWorkerId) => {
worker.on('exit', (code) => {
if (code !== 0) startWorker(app, kind, port, id);
else app.threads.delete(id);
if (impress.initialization) exit('Can not start Application server');
if (impress.initialization) exit('Can not start Application server', 1);
if (app.threads.size === 0) {
impress.applications.delete(app.path);
if (impress.applications.size === 0) impress.close();
Expand Down Expand Up @@ -123,14 +123,14 @@ const validateConfig = async (config) => {
valid = false;
}
}
if (!valid) exit('Application server configuration is invalid');
if (!valid) exit('Application server configuration is invalid', 1);
};

const loadApplication = async (root, dir, master) => {
impress.console.info(`Start: ${dir}`);
const configPath = path.join(dir, 'config');
const config = await new Config(configPath, CFG_OPTIONS).catch((error) => {
exit(`Can not read configuration: ${configPath}\n${error.stack}`);
exit(`Can not read configuration: ${configPath}\n${error.stack}`, 1);
});
await validateConfig(config);
if (master) {
Expand Down Expand Up @@ -194,7 +194,7 @@ const stop = async () => {
stopApplication(app.path);
}
await portsClosed;
exit('Application server stopped');
exit('Application server stopped', 0);
};

process.removeAllListeners('warning');
Expand Down
Loading