<commit_before>#!/usr/bin/env node

'use strict';

var path = require('path');
var exit = require('exit');

// this must be set before "server.js" is loaded
process.env.HARAKA = process.env.HARAKA || path.resolve('.');
try {
    require.paths.push(path.join(process.env.HARAKA, 'node_modules'));
}
catch (e) {
    process.env.NODE_PATH = process.env.NODE_PATH ?
            (process.env.NODE_PATH + ':' +
             path.join(process.env.HARAKA, 'node_modules'))
            :
            (path.join(process.env.HARAKA, 'node_modules'));
    require('module')._initPaths(); // Horrible hack
}

var fs     = require('fs');
var logger = require('./logger');
var server = require('./server');

exports.version = JSON.parse(
        fs.readFileSync(path.join(__dirname, './package.json'), 'utf8')
    ).version;

process.on('uncaughtException', function (err) {
    if (err.stack) {
        err.stack.split("\n").forEach(function (line) {
            logger.logcrit(line);
        });
    }
    else {
        logger.logcrit('Caught exception: ' + JSON.stringify(err));
    }
    logger.dump_logs();
    exit(1);
});

['SIGTERM', 'SIGINT'].forEach(function (sig) {
    process.on(sig, function () {
        process.title = path.basename(process.argv[1], '.js');
        logger.lognotice(sig + ' received');
        logger.dump_logs();
        exit(1);
    });
});

process.on('SIGHUP', function () {
    logger.lognotice("Flushing the temp fail queue");
    server.flushQueue();
});

process.on('exit', function() {
    process.title = path.basename(process.argv[1], '.js');
    logger.lognotice('Shutting down');
    logger.dump_logs();
    exit(0);
});

logger.log("NOTICE", "Starting up Haraka version " + exports.version);

server.createServer();<commit_msg>Fix on exit handlers<commit_after>#!/usr/bin/env node

'use strict';

var path = require('path');
var exit = require('exit');

// this must be set before "server.js" is loaded
process.env.HARAKA = process.env.HARAKA || path.resolve('.');
try {
    require.paths.push(path.join(process.env.HARAKA, 'node_modules'));
}
catch (e) {
    process.env.NODE_PATH = process.env.NODE_PATH ?
            (process.env.NODE_PATH + ':' +
             path.join(process.env.HARAKA, 'node_modules'))
            :
            (path.join(process.env.HARAKA, 'node_modules'));
    require('module')._initPaths(); // Horrible hack
}

var fs     = require('fs');
var logger = require('./logger');
var server = require('./server');

exports.version = JSON.parse(
        fs.readFileSync(path.join(__dirname, './package.json'), 'utf8')
    ).version;

process.on('uncaughtException', function (err) {
    if (err.stack) {
        err.stack.split("\n").forEach(function (line) {
            logger.logcrit(line);
        });
    }
    else {
        logger.logcrit('Caught exception: ' + JSON.stringify(err));
    }
    logger.dump_logs();
    exit(1);
});

['SIGTERM', 'SIGINT'].forEach(function (sig) {
    process.on(sig, function () {
        process.title = path.basename(process.argv[1], '.js');
        logger.lognotice(sig + ' received');
        logger.dump_logs();
        exit(1);
    });
});

process.on('SIGHUP', function () {
    logger.lognotice("Flushing the temp fail queue");
    server.flushQueue();
});

process.on('exit', function(code) {
    process.title = path.basename(process.argv[1], '.js');
    logger.lognotice('Shutting down');
    logger.dump_logs();
    exit(code);
});

logger.log("NOTICE", "Starting up Haraka version " + exports.version);

server.createServer();
{'fraction_non_alphanumeric': 0.1861912846632711, 'fraction_numerical': 0.00311262026032824, 'mean_word_length': 3.0632183908045976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6378370', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1149, 'n_words': 204}